The Fourth version
This commit is contained in:
52
MY/cnn.c
52
MY/cnn.c
@@ -1,6 +1,6 @@
|
||||
#include "cnn.h"
|
||||
|
||||
|
||||
u8 isrun;
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>*/
|
||||
void PrintfArray(float *array, int array_num, int elements_per_line)
|
||||
@@ -266,12 +266,20 @@ int calculate_probabilities(float *input_array, float *output_array, int input_n
|
||||
}
|
||||
|
||||
|
||||
void _cnn_run(){
|
||||
isrun = 1;
|
||||
}
|
||||
|
||||
|
||||
void cnn_run(){
|
||||
printf("CNNģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n");
|
||||
|
||||
for(int i=0;i<10;i++)printf("data[%d]: %f\r\n",i,data.array[i]);
|
||||
printf("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>һ<EFBFBD>㣡\r\n");
|
||||
printf("CNNģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\nData<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>Ϊ<EFBFBD><EFBFBD>%s\r\n",data.dname);
|
||||
DEBUG_PRINTF("data[%d]: %f\r\n",0,data.array[0]);
|
||||
DEBUG_PRINTF("data[%d]: %f\r\n",1,data.array[1]);
|
||||
DEBUG_PRINTF("data[%d]: %f\r\n",2,data.array[2]);
|
||||
DEBUG_PRINTF("data[%d]: %f\r\n",299,data.array[299]);
|
||||
DEBUG_PRINTF("data[%d]: %f\r\n",300,data.array[300]);
|
||||
DEBUG_PRINTF("data[%d]: %f\r\n",301,data.array[301]);
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>һ<EFBFBD>㣡\r\n");
|
||||
//1
|
||||
float* Full_output1 = (float*)mymalloc(SRAMEX, sizeof(float) * 102 * 102);
|
||||
Full(data.array, 100, Full_output1);
|
||||
@@ -297,7 +305,7 @@ void cnn_run(){
|
||||
for (int i = 0; i < 32; i++) {
|
||||
Pooling(Convolution_result1[i], 100, 2, 2, Pooling_result1[i]);
|
||||
}
|
||||
printf("<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\r\n");
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\r\n");
|
||||
//2
|
||||
myfree(SRAMEX, Full_output1);
|
||||
free2DArray(Convolution_result1_relu,32);
|
||||
@@ -334,7 +342,7 @@ void cnn_run(){
|
||||
for (int i = 0; i < 64; i++) {
|
||||
Pooling(Convolution_result2[i], 50, 2, 2, Pooling_result2[i]);
|
||||
}
|
||||
printf("<EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\r\n");
|
||||
DEBUG_PRINTF("<EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\r\n");
|
||||
//3
|
||||
myfree(SRAMEX, Full_output2);
|
||||
free2DArray(Pooling_result1,32);
|
||||
@@ -375,7 +383,7 @@ void cnn_run(){
|
||||
}
|
||||
float* xi = (float*)mymalloc(SRAMEX, sizeof(float) * 128 * 12 * 12);
|
||||
Flatten2D(Pooling_result3, 128, 12, xi);
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\r\n");
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\r\n");
|
||||
//4
|
||||
myfree(SRAMEX, Full_output3);
|
||||
free2DArray(Pooling_result2,64);
|
||||
@@ -383,30 +391,44 @@ void cnn_run(){
|
||||
free2DArray(Convolution_result3_relu,128);
|
||||
free2DArray(Convolution_result3_before,128);
|
||||
free2DArray(Convolution_result3,128);
|
||||
float yi[128] = {0};
|
||||
|
||||
//float yi[128] = {0};
|
||||
float *yi = (float *)mymalloc(SRAMEX, 128 * sizeof(float));
|
||||
memset(yi, 0, 128 * sizeof(float));
|
||||
|
||||
for (int i = 0; i < 128; i++) {
|
||||
float sum = 0;
|
||||
float* fc1_weight_new = (float*)mymalloc(SRAMEX, sizeof(float) * 128 * 12 * 12);
|
||||
memcpy(fc1_weight_new,&fc1_weight.array[i*128*12*12],128*12*12 * sizeof(float));
|
||||
sum = ConnectedLayer(xi, 128 * 12 * 12, fc1_weight_new, fc1_bias.array[i]);
|
||||
yi[i] = ReLU2(sum);
|
||||
myfree(SRAMEX, fc1_weight_new);
|
||||
}
|
||||
PrintfArray(yi,128,128);
|
||||
//printf("\n");
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\r\n");
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\r\n");
|
||||
//PrintfArray(yi,128,128);
|
||||
//5
|
||||
free2DArray(Pooling_result3,128);
|
||||
float zi[7] = { 0 };
|
||||
|
||||
//float zi[7] = { 0 };
|
||||
float *zi = (float *)mymalloc(SRAMEX, 7 * sizeof(float));
|
||||
memset(yi, 0, 7 * sizeof(float));
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
float fc2_weight_new[128];
|
||||
memcpy(fc2_weight_new,&fc2_weight.array[i*128],128 * sizeof(float));
|
||||
zi[i] = ConnectedLayer(yi, 128, fc2_weight_new, fc2_bias.array[i]);
|
||||
}
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\r\n");
|
||||
PrintfArray(zi,7,7);
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\r\n");
|
||||
//end
|
||||
float result[7];
|
||||
float *result = (float *)mymalloc(SRAMEX, 7 * sizeof(float));
|
||||
int max_probability_idx = calculate_probabilities(zi,result,7);
|
||||
PrintfArray(result,7,7);
|
||||
printf("%f, Label %d", result[max_probability_idx - 1] * 100, max_probability_idx);
|
||||
printf("%f, Label %d\r\n", result[max_probability_idx - 1] * 100, max_probability_idx);
|
||||
myfree(SRAMEX, xi);
|
||||
myfree(SRAMEX, yi);
|
||||
myfree(SRAMEX, zi);
|
||||
myfree(SRAMEX, result);
|
||||
isrun = 0;
|
||||
}
|
||||
|
||||
3
MY/cnn.h
3
MY/cnn.h
@@ -4,6 +4,8 @@
|
||||
#include <math.h>
|
||||
#include "my.h"
|
||||
|
||||
extern u8 isrun;
|
||||
|
||||
void PrintfArray(float *array, int array_num, int elements_per_line);
|
||||
void **allocate2DArray(int depth, int num, size_t elementSize);
|
||||
void free2DArray(float **array, int depth);
|
||||
@@ -20,6 +22,7 @@ void AddBias(float *inputArray, int input_num, float bias, float *outputArray);
|
||||
int calculate_probabilities(float *input_array, float *output_array, int input_num);
|
||||
void generateMatrix(float *get_data, float Max_value, int totalPoints, float CNN_data[100][100]);
|
||||
|
||||
void _cnn_run(void);
|
||||
void cnn_run(void);
|
||||
|
||||
#endif
|
||||
|
||||
16
MY/debug.c
16
MY/debug.c
@@ -15,7 +15,7 @@ void DEBUG(){
|
||||
|
||||
|
||||
|
||||
void DEBUG_PRINT(const char *fmt, ...) {
|
||||
void DEBUG_PRINTF(const char *fmt, ...) {
|
||||
if(_DEBUG){
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
@@ -30,15 +30,15 @@ void SDRAM_USED(){
|
||||
u8 RAM_ID = 0;
|
||||
u16 memused = 0;
|
||||
u8 paddr[20];
|
||||
memused=my_mem_perused(RAM_ID++);
|
||||
sprintf((char*)paddr,"%d.%01d%%",memused/10,memused%10);
|
||||
printf("\r\nSRAMʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%s\r\n",paddr);
|
||||
memused=my_mem_perused(RAM_ID++);
|
||||
sprintf((char*)paddr,"%d.%01d%%",memused/10,memused%10);
|
||||
printf("SDRAMʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%s\r\n",paddr);
|
||||
memused=my_mem_perused(RAM_ID);
|
||||
sprintf((char*)paddr,"%d.%01d%%",memused/10,memused%10);
|
||||
printf("[%d] %dʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%s\r\n",memused,RAM_ID++,paddr);
|
||||
memused=my_mem_perused(RAM_ID);
|
||||
sprintf((char*)paddr,"%d.%01d%%",memused/10,memused%10);
|
||||
printf("[%d] %dʹ<64><CAB9><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%s\r\n",memused,RAM_ID++,paddr);
|
||||
memused=my_mem_perused(RAM_ID);
|
||||
sprintf((char*)paddr,"%d.%01d%%",memused/10,memused%10);
|
||||
printf("[%d] %dʹ<64><CAB9><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%s\r\n",memused,RAM_ID++,paddr);
|
||||
printf("CCMʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%s\r\n",paddr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
#include "malloc.h"
|
||||
|
||||
void DEBUG(void);
|
||||
void DEBUG_PRINT(const char *fmt, ...);
|
||||
void DEBUG_PRINTF(const char *fmt, ...);
|
||||
void SDRAM_USED(void);
|
||||
void TIM3_Init(u16 arr,u16 psc);
|
||||
|
||||
340
MY/my.c
340
MY/my.c
@@ -15,6 +15,7 @@ Model fc2_weight;
|
||||
Model data;
|
||||
|
||||
|
||||
|
||||
float* modelmym_init(char* model_name){
|
||||
if(conv1_bias.array == NULL && strcmp(model_name, "conv1_bias") == 0)
|
||||
return conv1_bias.array = (float*)mymalloc(SRAMEX, CONV1_BIAS_ARRSIZE * sizeof(float));
|
||||
@@ -117,7 +118,7 @@ u8 modelmym_free(char* model_name){
|
||||
fc2_weight.realength = NULL;
|
||||
return 1;
|
||||
}
|
||||
else if(data.array != NULL && strcmp(model_name, "fc2_weight") == 0){
|
||||
else if(data.array != NULL && strcmp(model_name, "data") == 0){
|
||||
myfree(SRAMEX,data.array);
|
||||
data.array = NULL;
|
||||
data.realength = NULL;
|
||||
@@ -159,165 +160,165 @@ u8 model_write(char* model_name)
|
||||
|
||||
model_info("all");
|
||||
SDRAM_USED();
|
||||
}else {
|
||||
}else{
|
||||
u8 res=0;
|
||||
u8 _times=0;
|
||||
u32 _larr = 0;
|
||||
char _tmp[11] = "";
|
||||
char _path[20] = {0};
|
||||
char buffer[2] = {0};
|
||||
u8 _len = strlen(model_name);
|
||||
char _path[_len+1+7+30];
|
||||
char _fstr[READLENGTH+1] = {0};
|
||||
char _sstr[2];
|
||||
int progress;
|
||||
Model *_model = model(model_name);
|
||||
|
||||
printf("\r\n");
|
||||
if(_model == NULL || strcmp(model_name, "data") == 0){
|
||||
sprintf(_path, "0:/%s.txt", model_name);
|
||||
if(f_open(file, (const TCHAR *)_path, 1)){
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD>ģ<EFBFBD>ͻ<EFBFBD>Data<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n");
|
||||
return 199;
|
||||
}else{
|
||||
_model = model("data");
|
||||
_model -> dname = model_name;
|
||||
}
|
||||
}
|
||||
|
||||
Model *_model = NULL;
|
||||
if(_model -> dname == NULL){
|
||||
sprintf(_path, "0:/%s.txt", _model -> name);
|
||||
if(f_open(file, (TCHAR *)_path, 1)){
|
||||
DEBUG_PRINTF("Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>ͣ<EFBFBD>[%s]\r\n", _path);
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
if(_model -> array == NULL && modelmym_init(_model -> name) == NULL){
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD>[%s]<5D><><EFBFBD><EFBFBD><EFBFBD>鵽SDRAM<41><4D>\r\n", _model -> name);
|
||||
return 200;
|
||||
}
|
||||
|
||||
if(model(model_name)){
|
||||
_model = model(model_name);
|
||||
sprintf(_path, "0:/%s.txt",_model -> name);
|
||||
if(f_open(file,(const TCHAR*)_path,1)){
|
||||
DEBUG_PRINT("\r\n<EFBFBD>ļ<EFBFBD>[%s]<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>\r\n",_path);
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
else{
|
||||
sprintf(_path, "0:/%s.txt",model_name);
|
||||
if(f_open(file,(const TCHAR*)_path,1)){
|
||||
DEBUG_PRINT("\r\n<EFBFBD>ļ<EFBFBD>[%s]<5D><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>\r\n",_path);
|
||||
return 200;
|
||||
}
|
||||
_model = model("data");
|
||||
_model -> dname = model_name;
|
||||
*_tmp = NULL;
|
||||
}
|
||||
DEBUG_PRINT("\r\n<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%s\r\n",_path);
|
||||
if(_model -> array == NULL)modelmym_init(_model -> name);
|
||||
if(_model -> array == NULL){
|
||||
DEBUG_PRINT("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡģ<EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD>[%s]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",_model -> name);
|
||||
return 201;
|
||||
}
|
||||
if(_model -> dname) DEBUG_PRINT("ʹ<EFBFBD>õ<EFBFBD>data<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>Ϊ<EFBFBD><EFBFBD>%s\r\n",_model -> dname);
|
||||
else DEBUG_PRINT("ģ<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%s\r\n",_model -> name);
|
||||
printf("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>%s<><73><EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD>......\r\n",_model -> name);
|
||||
while(_larr < _model -> maxlength){
|
||||
res=f_read(file,fatbuf,11*1,&br);
|
||||
DEBUG_PRINTF("д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>%s\r\n", _model -> name);
|
||||
if(_model -> dname)DEBUG_PRINTF("д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Data<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><EFBFBD>ǣ<EFBFBD>%s\r\n", _model -> dname);
|
||||
DEBUG_PRINTF("д<EFBFBD><EFBFBD>ģ<EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d\r\n", _model -> maxlength);
|
||||
DEBUG_PRINTF("Ŀǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d\r\n", _model -> realength);
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ģ<EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD>'%s'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD>......\r\n",_model -> dname ? _model -> dname : _model -> name);
|
||||
|
||||
while(1){
|
||||
res = f_read(file, fatbuf, READLENGTH ,&br);
|
||||
if(res){
|
||||
DEBUG_PRINT("<EFBFBD><EFBFBD>ȡ[%s]<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>:%d\r\n",_path,res);
|
||||
return 202;
|
||||
}
|
||||
else{
|
||||
for(u32 i=0;i<br;i++){
|
||||
if(fatbuf[i]==0x0d){
|
||||
float value = atof(_tmp);
|
||||
*_tmp = NULL;
|
||||
_model -> array[_larr++] = value;
|
||||
//DEBUG_PRINT("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[string]: %s\r\n",i,_readtmp);
|
||||
//DEBUG_PRINT("<22>س<EFBFBD>[%d] <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[float]: %f\r\n",i+1,value);
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d\r\n",res);
|
||||
return res;
|
||||
}else{
|
||||
for(int i=0; i < br; i++){
|
||||
if(fatbuf[i] == 0x0d){
|
||||
float _fvalue = atof(_fstr);
|
||||
_model -> array[_larr++] = _fvalue;
|
||||
//DEBUG_PRINTF("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[string]: %s\r\n<>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[float]: %f\r\n",i,_fstr,_fvalue);
|
||||
i++;
|
||||
*_fstr = NULL;
|
||||
_model -> realength = _larr; //_larr<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(_larr >= _model -> maxlength)break;
|
||||
}else{
|
||||
sprintf(buffer, "%c", fatbuf[i]);
|
||||
strcat(_tmp, buffer);
|
||||
//DEBUG_PRINT("[%d]: %c\r\n",i,fatbuf[i]);
|
||||
sprintf(_sstr, "%c", fatbuf[i]);
|
||||
strcat(_fstr, _sstr);
|
||||
//DEBUG_PRINTF("[%d]_fstr is[%s], _sstr is[%s], fatbuf is [%c]\r\n",i,_fstr,_sstr,fatbuf[i]);
|
||||
}
|
||||
}
|
||||
if(_model -> maxlength >= 73728 && (_larr % (_model -> maxlength/10) == 0 || _larr >= _model -> maxlength || _larr == 1)) {
|
||||
progress = _larr >= _model -> maxlength ? 100 : _larr == 1 ? 0 : progress + 10;
|
||||
DEBUG_PRINT("\r\n[");
|
||||
if(_model -> maxlength >= 73728 && (_larr >= (_model -> maxlength/10)*_times)){
|
||||
progress = _larr >= _model -> maxlength ? 100 : _times++ == 0 ? 0 : progress + 10;
|
||||
printf("\r\n[");
|
||||
for(u16 j=0; j<50;j++){
|
||||
if(j < progress/2) printf("=");
|
||||
else DEBUG_PRINT(" ");
|
||||
else printf(" ");
|
||||
}
|
||||
printf("] %d%%", progress);
|
||||
}
|
||||
if(_larr >= _model -> maxlength)break;
|
||||
}
|
||||
}
|
||||
_model -> realength = _larr; //_larr<72><72><EFBFBD><EFBFBD>ֵΪģ<CEAA><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
DEBUG_PRINT("\r\n[%s]<5D><>ģ<EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>뵽<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>! ģ<>ͳ<EFBFBD><CDB3><EFBFBD>Ϊ %d\r\n",_model -> name,_model -> realength);
|
||||
return res;
|
||||
DEBUG_PRINTF("\r\nģ<EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD>[%s]<5D><>д<EFBFBD>뵽<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>! ģ<>ͳ<EFBFBD><CDB3><EFBFBD>Ϊ %d\r\n",_model -> dname ? _model -> dname : _model -> name,_model -> realength);
|
||||
return 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void model_read(char* model_name, u32 gap){
|
||||
u8 model_read(char* model_name, u32 start, u32 end, u32 gap){
|
||||
if(strcmp(model_name, "all") == 0){
|
||||
model_read("conv1_bias", gap);
|
||||
model_read("conv1_weight", gap);
|
||||
model_read("conv2_bias", gap);
|
||||
model_read("conv2_weight", gap);
|
||||
model_read("conv3_bias", gap);
|
||||
model_read("conv3_weight", gap);
|
||||
model_read("fc1_bias", gap);
|
||||
model_read("fc1_weight", gap);
|
||||
model_read("fc2_bias", gap);
|
||||
model_read("fc2_weight", gap);
|
||||
model_read("data", gap);
|
||||
}else {
|
||||
model_read("conv1_bias", start, end, gap);
|
||||
model_read("conv1_weight", start, end, gap);
|
||||
model_read("conv2_bias", start, end, gap);
|
||||
model_read("conv2_weight", start, end, gap);
|
||||
model_read("conv3_bias", start, end, gap);
|
||||
model_read("conv3_weight", start, end, gap);
|
||||
model_read("fc1_bias", start, end, gap);
|
||||
model_read("fc1_weight", start, end, gap);
|
||||
model_read("fc2_bias", start, end, gap);
|
||||
model_read("fc2_weight", start, end, gap);
|
||||
model_read("data", start, end, gap);
|
||||
}else{
|
||||
Model *_model = model(model_name);
|
||||
for (int i=0;i<((_model -> realength/gap)+(_model -> realength%gap ? 2 : 1));i++)
|
||||
printf("\r\n%s_floatArray[%d]: %f",_model -> name,i*gap<_model -> realength ? i*gap : _model -> realength-1,i*gap<_model -> realength ? _model -> array[i*gap] : _model -> array[_model -> realength-1]);
|
||||
printf("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
u8 switch_data(char* data_name){
|
||||
char _path[20] = {0};
|
||||
|
||||
sprintf(_path, "0:/%s.txt",data_name);
|
||||
if(f_open(file,(const TCHAR*)_path,1)){
|
||||
DEBUG_PRINT("\r\n<EFBFBD>ļ<EFBFBD>[%s]<5D><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>\r\n",_path);
|
||||
return 200;
|
||||
}
|
||||
|
||||
DEBUG_PRINT("\r\n<EFBFBD>µ<EFBFBD>data<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%s",_path);
|
||||
model_write(data_name);
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><EFBFBD><EFBFBD> %s.txt\r\n",data_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
u8 sd_read(u32 length, char* model_name, u32 gap)
|
||||
{
|
||||
u8 res=0;
|
||||
u32 _larr = 0;
|
||||
char _tmp[11] = "";
|
||||
char _path[20] = {0};
|
||||
|
||||
float* floatArray = NULL;
|
||||
Model *_model = model(model_name);
|
||||
|
||||
if(length >= _model -> maxlength)length = _model -> maxlength -1;
|
||||
floatArray = modelmym_init(model_name);
|
||||
if(floatArray == NULL){
|
||||
DEBUG_PRINT("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return 7;
|
||||
}
|
||||
sprintf(_path, "0:/%s.txt",model_name);
|
||||
f_open(file,(const TCHAR*)_path,1);//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
while(_larr <= length){
|
||||
res=f_read(file,fatbuf,11,&br);
|
||||
if(res)DEBUG_PRINT("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d\r\n",res);
|
||||
else{
|
||||
for(u32 i=0;i<br;i++){
|
||||
if(fatbuf[i]==0x0d){
|
||||
float value = atof(_tmp);
|
||||
memset(_tmp, 0, sizeof(_tmp));
|
||||
floatArray[_larr++] = value;
|
||||
DEBUG_PRINT("<EFBFBD>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[string]: %s\r\n",i,_tmp);
|
||||
DEBUG_PRINT("<EFBFBD>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[float]: %f\r\n",i+1,value);
|
||||
}else{
|
||||
char buffer[2];
|
||||
sprintf(buffer, "%c", fatbuf[i]);
|
||||
strcat(_tmp, buffer);
|
||||
DEBUG_PRINT("[%d]: %c\r\n",i,fatbuf[i]);
|
||||
}
|
||||
}
|
||||
if(_model == NULL || end == 0 || start > _model -> realength || end > _model -> realength)return NULL;
|
||||
if(_model -> realength){
|
||||
for (u32 i=0;i<((end > (_model -> realength) ? _model -> realength : (end-start))+(end > (_model -> realength) ? _model -> realength : (end-start)%gap ? 2 : 1));i+=gap)
|
||||
printf("\r\n%s_floatArray[%d]: %f",_model->name,(i+start)<_model->realength ? i+start : _model->realength-1,(i+start)<_model->realength ? _model->array[i+start] : _model->array[_model -> realength-1]);
|
||||
printf("\r\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
for (int i=0;i<((length/gap)+(length%gap ? 2 : 1));i++)
|
||||
printf("\r\nfloatArray[%d]: %f",i*gap<=length ? i*gap : length,i*gap<=length ? floatArray[i*gap] : floatArray[length]);
|
||||
printf("\r\n");
|
||||
return res;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
u8 model_switchdata(char* data_name){
|
||||
u8 _len = strlen(data_name);
|
||||
char _path[_len+1+7];
|
||||
if(data.array != NULL)modelmym_free("data");
|
||||
sprintf(_path, "0:/%s.txt",data_name);
|
||||
if(f_open(file,(const TCHAR*)_path,1)){
|
||||
DEBUG_PRINTF("\r\nData<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>[%s]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n",data_name);
|
||||
return NULL;
|
||||
}else{
|
||||
u8 _res = model_write(data_name);
|
||||
if (_res == NULL) {
|
||||
DEBUG_PRINTF("Data<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>[%s]<5D>л<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>\r\n",data_name);
|
||||
return NULL;
|
||||
}
|
||||
else printf("Data<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>[%s]<5D>л<EFBFBD><D0BB>ɹ<EFBFBD><C9B9><EFBFBD>\r\n",data_name);
|
||||
DEBUG_PRINTF("data_name<EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d\r\n_path<EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d\r\n_pathΪ<EFBFBD><EFBFBD>%s\r\n",_len,sizeof(_path),_path);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void model_dataset(){
|
||||
printf("\r\ndataset is: %s\r\n",data.dname);
|
||||
}
|
||||
|
||||
u8 model_info(char* model_name){
|
||||
if(strcmp(model_name, "all") == 0){
|
||||
model_info("conv1_bias");
|
||||
model_info("conv1_weight");
|
||||
model_info("conv2_bias");
|
||||
model_info("conv2_weight");
|
||||
model_info("conv3_bias");
|
||||
model_info("conv3_weight");
|
||||
model_info("fc1_bias");
|
||||
model_info("fc1_weight");
|
||||
model_info("fc2_bias");
|
||||
model_info("fc2_weight");
|
||||
model_info("data");
|
||||
return 1;
|
||||
}else if(model(model_name)){
|
||||
Model *_model = model(model_name);
|
||||
printf("\r\nmodel.name is: %s\r\n",_model -> name);
|
||||
printf("model.array.address is: 0X%X\r\n",_model -> array);
|
||||
printf("model.maxlength is: %d\r\n",_model -> maxlength);
|
||||
printf("model.realength is: %d\r\n",_model -> realength);
|
||||
//if(strcmp(_model -> name, "data") == 0)printf("dataset is: %s\r\n",_model -> dname); <20>⺯<EFBFBD><E2BAAF><EFBFBD><EFBFBD>BUG<55><47><EFBFBD><EFBFBD>model_dataset<65><74><EFBFBD><EFBFBD>
|
||||
return 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -339,30 +340,6 @@ void* model(char* model_name){
|
||||
|
||||
|
||||
|
||||
void model_info(char* model_name){
|
||||
if(strcmp(model_name, "all") == 0){
|
||||
model_info("conv1_bias");
|
||||
model_info("conv1_weight");
|
||||
model_info("conv2_bias");
|
||||
model_info("conv2_weight");
|
||||
model_info("conv3_bias");
|
||||
model_info("conv3_weight");
|
||||
model_info("fc1_bias");
|
||||
model_info("fc1_weight");
|
||||
model_info("fc2_bias");
|
||||
model_info("fc2_weight");
|
||||
model_info("data");
|
||||
}else {
|
||||
Model *_model = model(model_name);
|
||||
printf("\r\nmodel.name is: %s\r\n",_model -> name);
|
||||
printf("model.array.address is: 0X%X\r\n",_model -> array);
|
||||
printf("model.maxlength is: %d\r\n",_model -> maxlength);
|
||||
printf("model.realength is: %d\r\n",_model -> realength);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void model_init(){
|
||||
|
||||
conv1_bias.name = "conv1_bias";
|
||||
@@ -408,4 +385,51 @@ void model_init(){
|
||||
data.name = "data";
|
||||
data.array = modelmym_init(data.name);
|
||||
data.maxlength = DATA_ARRSIZE;
|
||||
data.dname = "data";
|
||||
}
|
||||
|
||||
|
||||
|
||||
u8 sd_read(u32 length, char* model_name, u32 gap)
|
||||
{
|
||||
u8 res=0;
|
||||
u32 _larr = 0;
|
||||
char _tmp[11] = "";
|
||||
char _path[20] = {0};
|
||||
|
||||
float* floatArray = NULL;
|
||||
Model *_model = model(model_name);
|
||||
|
||||
if(length >= _model -> maxlength)length = _model -> maxlength -1;
|
||||
floatArray = modelmym_init(model_name);
|
||||
if(floatArray == NULL){
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return 7;
|
||||
}
|
||||
sprintf(_path, "0:/%s.txt",model_name);
|
||||
f_open(file,(const TCHAR*)_path,1);//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
while(_larr <= length){
|
||||
res=f_read(file,fatbuf,11,&br);
|
||||
if(res)DEBUG_PRINTF("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d\r\n",res);
|
||||
else{
|
||||
for(u32 i=0;i<br;i++){
|
||||
if(fatbuf[i]==0x0d){
|
||||
float value = atof(_tmp);
|
||||
memset(_tmp, 0, sizeof(_tmp));
|
||||
floatArray[_larr++] = value;
|
||||
DEBUG_PRINTF("<EFBFBD>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[string]: %s\r\n",i,_tmp);
|
||||
DEBUG_PRINTF("<EFBFBD>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[float]: %f\r\n",i+1,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<((length/gap)+(length%gap ? 2 : 1));i++)
|
||||
printf("\r\nfloatArray[%d]: %f",i<=length ? i : length,i<=length ? floatArray[i] : floatArray[length]);
|
||||
printf("\r\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
32
MY/my.h
32
MY/my.h
@@ -25,6 +25,7 @@ typedef struct {
|
||||
|
||||
|
||||
|
||||
#define READLENGTH 11*10
|
||||
#define CONV1_BIAS_ARRSIZE 32
|
||||
#define CONV1_WEIGHT_ARRSIZE 32*1*3*3 //288
|
||||
#define CONV2_BIAS_ARRSIZE 64
|
||||
@@ -35,7 +36,7 @@ typedef struct {
|
||||
#define FC1_WEIGHT_ARRSIZE 128*18432 //2359296
|
||||
#define FC2_BIAS_ARRSIZE 7
|
||||
#define FC2_WEIGHT_ARRSIZE 7*128 //896
|
||||
#define DATA_ARRSIZE 100*100 //10000
|
||||
#define DATA_ARRSIZE 100*100 //10000
|
||||
|
||||
|
||||
|
||||
@@ -56,12 +57,13 @@ extern Model data;
|
||||
float* modelmym_init(char* model_name);
|
||||
u8 modelmym_free(char* model_name);
|
||||
u8 model_write(char* model_name);
|
||||
void model_read(char* model_name, u32 gap);
|
||||
u8 switch_data(char* data_name);
|
||||
u8 sd_read(u32 length, char* model_name,u32 gap);
|
||||
u8 model_read(char* model_name, u32 start, u32 end, u32 gap);
|
||||
u8 model_switchdata(char* model_name);
|
||||
void model_dataset(void);
|
||||
u8 model_info(char* model_name);
|
||||
void* model(char* model_name);
|
||||
void model_info(char* model_name);
|
||||
void model_init(void);
|
||||
u8 sd_read(u32 length, char* model_name,u32 gap);
|
||||
|
||||
|
||||
|
||||
@@ -104,23 +106,23 @@ for(u8 a; a<?; a++)
|
||||
// {
|
||||
// for(int i=0;i<length;i++){
|
||||
// if(fatbuf[i]==0x0d){
|
||||
// DEBUG_PRINT("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[string]: %s\r\n",i,_tmp);
|
||||
// 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_PRINT("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[float]: %f\r\n",i,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_PRINT("[%d]: %c\r\n",i,fatbuf[i]);
|
||||
// DEBUG_PRINTF("[%d]: %c\r\n",i,fatbuf[i]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// for (int i=0;i<_larr;i++){
|
||||
// DEBUG_PRINT("floatArray[%d]: %f\r\n",i,floatArray[i]);
|
||||
// DEBUG_PRINTF("floatArray[%d]: %f\r\n",i,floatArray[i]);
|
||||
// }
|
||||
// return res;
|
||||
//}
|
||||
@@ -143,17 +145,17 @@ for(u8 a; a<?; a++)
|
||||
// else{
|
||||
// for(int i=0;i<br;i++){
|
||||
// if(fatbuf[i]==0x0d){
|
||||
// DEBUG_PRINT("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[string]: %s\r\n",i,_tmp);
|
||||
// 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_PRINT("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[float]: %f\r\n",i,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_PRINT("[%d]: %c\r\n",i,fatbuf[i]);
|
||||
// DEBUG_PRINTF("[%d]: %c\r\n",i,fatbuf[i]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -165,17 +167,17 @@ for(u8 a; a<?; a++)
|
||||
// else{
|
||||
// for(int i=0;i<br;i++){
|
||||
// if(fatbuf[i]==0x0d){
|
||||
// DEBUG_PRINT("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[string]: %s\r\n",i,_tmp);
|
||||
// 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_PRINT("<22>س<EFBFBD>[%d] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[float]: %f\r\n",i,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_PRINT("[%d]: %c\r\n",i,fatbuf[i]);
|
||||
// DEBUG_PRINTF("[%d]: %c\r\n",i,fatbuf[i]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user