添加功能:sendblock

验证通过
This commit is contained in:
Qiea
2024-11-12 10:59:42 +08:00
parent edd76c2871
commit 15e6a6e1dc
6 changed files with 94 additions and 6 deletions

View File

@@ -278,7 +278,7 @@ void cnn_run(){
calculate_statistics(data,&value[0]);
if (check_threshold(data,&value[0])){
float* _data = generateMatrix(data,&value[0]);
send_blocks(_data);
DEBUG_PRINTF("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>\r\n");
//<2F><>һ<EFBFBD><EFBFBD><E3A3BA><EFBFBD><EFBFBD>102 * 102
@@ -286,12 +286,14 @@ void cnn_run(){
float* conv_rlst_1 = convolution(conv1_weight,conv1_bias,expand_matrix_1, 102);
float* pool_rslt_1 = pooling(conv1_weight, conv_rlst_1, 100);
{
myfree(SRAMEX,_data);
_data = NULL;
myfree(SRAMEX,expand_matrix_1);
expand_matrix_1 = NULL;
myfree(SRAMEX,conv_rlst_1);
conv_rlst_1 = NULL;
}
DEBUG_PRINTF("<EFBFBD><EFBFBD>ʼ<EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD>\r\n");
@@ -300,13 +302,14 @@ void cnn_run(){
float* conv_rlst_2 = convolution(conv2_weight,conv2_bias,expand_matrix_2, 52);
float* pool_rslt_2 = pooling(conv2_weight, conv_rlst_2, 50);
{
myfree(SRAMEX,pool_rslt_1);
pool_rslt_1 = NULL;
myfree(SRAMEX,expand_matrix_2);
expand_matrix_2 = NULL;
myfree(SRAMEX,conv_rlst_2);
conv_rlst_2 = NULL;
}
DEBUG_PRINTF("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n");
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3A3BA><EFBFBD><EFBFBD> 64 * 27 * 27
@@ -314,12 +317,14 @@ void cnn_run(){
float* conv_rlst_3 = convolution(conv3_weight,conv3_bias,expand_matrix_3, 27);
float* pool_rslt_3 = pooling(conv3_weight, conv_rlst_3, 25);
{
myfree(SRAMEX,pool_rslt_2);
pool_rslt_2 = NULL;
myfree(SRAMEX,expand_matrix_3);
expand_matrix_3 = NULL;
myfree(SRAMEX,conv_rlst_3);
conv_rlst_3 = NULL;
}
DEBUG_PRINTF("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>\r\n");
float* affine1_rslt = hidden(pool_rslt_3);
@@ -327,12 +332,14 @@ void cnn_run(){
DEBUG_PRINTF("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n");
float* affine2_rslt = output(affine1_rslt);
{
myfree(SRAMEX,pool_rslt_3);
pool_rslt_3 = NULL;
myfree(SRAMEX,affine1_rslt);
affine1_rslt = NULL;
myfree(SRAMEX,affine2_rslt);
affine2_rslt = NULL;
}
} else{
printf("δ<EFBFBD>ŵ磡<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ:%f ƽ<><C6BD>ֵ:%f <20><>׼<EFBFBD><D7BC>:%f\r\n",value[0],value[1],value[2]);

View File

@@ -4,6 +4,7 @@
#include "malloc.h"
#include <stdio.h>
#include <math.h>
#include "tools.h"
void cnn_run(void);
void _cnn_run(void);

64
PORTING/CNN/tools.c Normal file
View File

@@ -0,0 +1,64 @@
#include "tools.h"
void send_blocks(float* arr){
char uuid_str[9];
u32 time_stamp = HAL_GetTick();
u32 random_part = rand();
snprintf(uuid_str, 9, // 16 λ UUID<49><44>8 <20><><EFBFBD>ַ<EFBFBD> + <20><><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
"%04lX%04lX",
(unsigned long)(time_stamp & 0xFFFF),
(unsigned long)(random_part & 0xFFFF));
// <20><><EFBFBD><EFBFBD><E9B4A6> ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>洢1000<30><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
char* block = (char*) mymalloc(SRAMEX,sizeof(char)*100*100);
memset(block, 0 ,sizeof(char)*100*100);
int block_index = 0;
int _total_len = 0;
int total_len = 0;
for (int i = 0; i < 100; ++i) {
for (int j = 0; j < 100; ++j) {
int n = snprintf(block + block_index, 100 * 100 - block_index, "%.6f|", arr[i * 100 + j]);
block_index += n;
if (block_index >= 9000) {
block_index = 0; // <20><><EFBFBD>ÿ<EFBFBD>
_total_len++;
}
}
}
if (!block_index)_total_len--;
block_index = 0;
for (int i = 0; i < 100; ++i) {
for (int j = 0; j < 100; ++j) {
int n = snprintf(block + block_index, 100*100 - block_index, "%.6f|", arr[i*100+j]);
block_index += n;
if (block_index >= 9000) {
char* _block = (char*) mymalloc(SRAMEX,sizeof(char)*100*100);
memset(_block, 0 ,sizeof(char)*100*100);
block_index = 0; // <20><><EFBFBD>ÿ<EFBFBD>
sprintf(_block, "{\"uuid\":\"%s\",\"Bid\":\"%d\",\"Eid\":\"%d\",\"Block\":\"%s\"}\n", uuid_str, total_len++, _total_len, block);
printf("%s", _block);
myfree(SRAMEX,_block);
_block = NULL;
}
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
if (block_index > 0) {
char* _block = (char*) mymalloc(SRAMEX,sizeof(char)*100*100);
memset(_block, 0 ,sizeof(char)*100*100);
block_index = 0;
sprintf(_block, "{\"uuid\":\"%s\",\"Bid\":\"%d\",\"Eid\":\"%d\",\"Block\":\"%s\"}\n", uuid_str, total_len, _total_len, block);
printf("%s", _block);
myfree(SRAMEX,_block);
_block = NULL;
}
myfree(SRAMEX,block);
block = NULL;
}

6
PORTING/CNN/tools.h Normal file
View File

@@ -0,0 +1,6 @@
#include "cnn_model.h"
#include "debug.h"
void send_blocks(float* arr);

View File

@@ -677,6 +677,11 @@
<FileType>1</FileType>
<FilePath>..\PORTING\CNN\cnn.c</FilePath>
</File>
<File>
<FileName>tools.c</FileName>
<FileType>1</FileType>
<FilePath>..\PORTING\CNN\tools.c</FilePath>
</File>
</Files>
</Group>
</Groups>

View File

@@ -18,6 +18,7 @@
#include "cnn_model.h"
#include "debug.h"
#include "cnn.h"
#include "tools.h"
@@ -130,10 +131,14 @@ int main(void)
LED0=!LED0;
}
model_write("all");
printf("初始化完成!\r\n");
run_dataset();
SDRAM_USED();
// model_write("all");
// printf("初始化完成!\r\n");
// run_dataset();
// SDRAM_USED();
model_switchdata("C1autosave00095_right_new_2");
cnn_run();
while(1){
if(isrun)cnn_run();
}