移植c_cnn代码

This commit is contained in:
Qiea
2024-11-11 18:17:48 +08:00
parent 88ab12182e
commit 8d49d67929
4 changed files with 292 additions and 709 deletions

View File

@@ -19,22 +19,30 @@ typedef struct {
float* array;
u32 maxlength;
u32 realength;
u8 channel;
u8 num_kernels;
} Model;
#define READLENGTH 11*10
#define CONV1_BIAS_ARRSIZE 32
#define CONV1_WEIGHT_ARRSIZE 32*1*3*3 //288
#define CONV2_BIAS_ARRSIZE 64
#define CONV2_WEIGHT_ARRSIZE 64*32*3*3 //18432
#define CONV3_BIAS_ARRSIZE 128
#define CONV3_WEIGHT_ARRSIZE 128*64*3*3 //73728
#define FC1_BIAS_ARRSIZE 128
#define FC1_WEIGHT_ARRSIZE 128*18432 //2359296
#define FC2_BIAS_ARRSIZE 7
#define FC2_WEIGHT_ARRSIZE 7*128 //896
#define DATA_ARRSIZE 1250000 //1250000
#define READLENGTH (11*10)
#define CONV1_BIAS_ARRSIZE (32)
#define CONV1_WEIGHT_ARRSIZE (32*1*3*3) //288
#define CONV2_BIAS_ARRSIZE (64)
#define CONV2_WEIGHT_ARRSIZE (64*32*3*3) //18432
#define CONV3_BIAS_ARRSIZE (128)
#define CONV3_WEIGHT_ARRSIZE (128*64*3*3) //73728
#define FC1_BIAS_ARRSIZE (128)
#define FC1_WEIGHT_ARRSIZE (128*18432) //2359296
#define FC2_BIAS_ARRSIZE (7)
#define FC2_WEIGHT_ARRSIZE (7*128) //896
#if 1
#define DATA_ARRSIZE (1250000)
#else
#define DATA_ARRSIZE (100 * 100)
#endif
@@ -75,116 +83,4 @@ u8 sd_read(u32 length, char* model_name,u32 gap);
//fc1_weight[a*18432+b*1] a:0~127 b:0~18431
//fc2_bias[a*1] a:0~6
//fc2_weight[a*128+b*1] a:0~6 b:0~127
/*--------------------------------
for(u8 a; a<?; a++)
--------------------------------*/
//u8 sd_read(u16 length)
//{
// u8 res=0;
// char _tmp[11] = "";
// float floatArray[32] = {0};
// int _larr = 0;
// printf("\r\nRead file data is:\r\n");
// res=f_read(file,fatbuf,length,&br);
// if(res) //<2F><><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD>
// {
// printf("\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD>:%d\r\n",res);
// }else
// {
// for(int i=0;i<length;i++){
// if(fatbuf[i]==0x0d){
// DEBUG_PRINTF("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[string]: %s\r\n",i,_tmp);
// i++;
// float value = atof(_tmp);
// memset(_tmp, 0, sizeof(_tmp));
// floatArray[_larr++] = value;
// DEBUG_PRINTF("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[float]: %f\r\n",i,value);
// }else{
// char buffer[2];
// sprintf(buffer, "%c", fatbuf[i]);
// strcat(_tmp, buffer);
// DEBUG_PRINTF("[%d]: %c\r\n",i,fatbuf[i]);
// }
// }
// }
// for (int i=0;i<_larr;i++){
// DEBUG_PRINTF("floatArray[%d]: %f\r\n",i,floatArray[i]);
// }
// return res;
//}
//u8 sd_read(u16 length, char* model)
//{
// float* floatArray = NULL;
// if((floatArray = model_init(model)) == NULL)printf("<22><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
// u8 res=0;
// char _tmp[11] = "";
// u32 _larr = 0;
// length = length*11;
// printf("\r\nRead file data is:\r\n");
// for(int i=0;i<length/512;i++){
// res=f_read(file,fatbuf,512,&br);
// if(res)printf("\r\n<><6E><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD>:%d\r\n",res);
// else{
// for(int i=0;i<br;i++){
// if(fatbuf[i]==0x0d){
// DEBUG_PRINTF("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[string]: %s\r\n",i,_tmp);
// i++;
// float value = atof(_tmp);
// memset(_tmp, 0, sizeof(_tmp));
// floatArray[_larr++] = value;
// DEBUG_PRINTF("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[float]: %f\r\n",i,value);
// }else{
// char buffer[2];
// sprintf(buffer, "%c", fatbuf[i]);
// strcat(_tmp, buffer);
// DEBUG_PRINTF("[%d]: %c\r\n",i,fatbuf[i]);
// }
// }
// }
// }
// if(length%512){
// res=f_read(file,fatbuf,length%512,&br);
// if(res)printf("\r\nRead Error:%d\r\n",res);
// else{
// for(int i=0;i<br;i++){
// if(fatbuf[i]==0x0d){
// DEBUG_PRINTF("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[string]: %s\r\n",i,_tmp);
// i++;
// float value = atof(_tmp);
// memset(_tmp, 0, sizeof(_tmp));
// floatArray[_larr++] = value;
// DEBUG_PRINTF("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[float]: %f\r\n",i,value);
// }else{
// char buffer[2];
// sprintf(buffer, "%c", fatbuf[i]);
// strcat(_tmp, buffer);
// DEBUG_PRINTF("[%d]: %c\r\n",i,fatbuf[i]);
// }
// }
// }
// }
// for (int i=0;i<_larr/10;i++){
// printf("floatArray[%d]: %f\r\n",i*10,floatArray[i*10]);
// }
// return res;
//}
#endif