MINI版本

This commit is contained in:
Qiea
2024-12-18 11:28:00 +08:00
parent fbc771d3a3
commit 13d21f152c
22 changed files with 5052735 additions and 333 deletions

View File

@@ -57,7 +57,7 @@ float* modelmym_init(char* model_name){
u8 modelmym_free(char* model_name){
uint8_t modelmym_free(char* model_name){
if(conv1_bias.array != NULL && strcmp(model_name, "conv1_bias") == 0){
free(conv1_bias.array);
conv1_bias.array = NULL;
@@ -143,7 +143,7 @@ u8 modelmym_free(char* model_name){
u8 model_write(char* model_name)
uint8_t model_write(char* model_name)
{
if(strcmp(model_name, "all") == 0){
model_write("conv1_bias");
@@ -158,11 +158,10 @@ u8 model_write(char* model_name)
model_write("fc2_weight");
model_info("all");
SDRAM_USED();
}else{
u8 _times=0;
u32 _larr = 0;
u8 _len = strlen(model_name);
uint8_t _times=0;
uint32_t _larr = 0;
uint8_t _len = strlen(model_name);
char _path[_len+1+7+30];
char _datapath[_len+1+7+30];
char _fstr[READLENGTH+1] = {0};
@@ -173,7 +172,7 @@ u8 model_write(char* model_name)
sprintf(_path, "./dataset/_data/%s.txt", model_name);
FILE *file = fopen(_path, "r");
if(file == NULL){
DEBUG_PRINTF("\r\n输入了一个无效的模型或Data数据集的名字\r\n");
printf("\r\n<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");
@@ -185,13 +184,13 @@ u8 model_write(char* model_name)
sprintf(_path, "./dataset/%s.txt", _model -> name);
FILE *file = fopen(_path, "r");
if(file == NULL){
DEBUG_PRINTF("预设里没有这个模型:[%s]\r\n", _path);
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("无法创建模型参数[%s]的数组到SDRAM\r\n", _model -> name);
printf("<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD>[%s]<5D><><EFBFBD><EFBFBD><EFBFBD>SDRAM<EFBFBD><EFBFBD>\r\n", _model -> name);
return 200;
}
@@ -199,40 +198,40 @@ u8 model_write(char* model_name)
sprintf(_path, "./dataset/%s.txt", _model -> dname ? _datapath : _model -> name);
FILE *file = fopen(_path, "r");
if(file == NULL){
DEBUG_PRINTF("文件[%s]无法打开\r\n", _model -> dname ? _model -> dname : _model -> name);
printf("<EFBFBD>ļ<EFBFBD>[%s]<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n", _model -> dname ? _model -> dname : _model -> name);
return 199;
}
DEBUG_PRINTF("写入的模型参数名字是:%s\r\n", _model -> name);
if(_model -> dname)DEBUG_PRINTF("写入的Data数据集是%s\r\n", _model -> dname);
DEBUG_PRINTF("写入模型参数数组的最大长度为:%d\r\n", _model -> maxlength);
DEBUG_PRINTF("目前数组存活的元素数量为:%d", _model -> realength);
printf("\r\n正在写入模型参数'%s',请稍后......\r\n",_model -> dname ? _model -> dname : _model -> name);
printf("д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>%s\r\n", _model -> name);
if(_model -> dname)printf("д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Data<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><EFBFBD>ǣ<EFBFBD>%s\r\n", _model -> dname);
printf("д<EFBFBD><EFBFBD>ģ<EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󳤶<EFBFBD>Ϊ<EFBFBD><EFBFBD>%d\r\n", _model -> maxlength);
printf("Ŀǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d", _model -> realength);
printf("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ģ<EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD>'%s'<27><><EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD>......\r\n",_model -> dname ? _model -> dname : _model -> name);
while(_larr < _model->maxlength && fgets(_fstr, sizeof(_fstr), file) != NULL){
char *endptr;
float value = strtof(_fstr, &endptr);
// 检查是否转换成功
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
if (endptr == _fstr) {
fprintf(stderr, " %d 行不是有效的浮点数: %s", _larr + 1, _fstr);
continue; // 跳过无效行
fprintf(stderr, "<EFBFBD><EFBFBD> %d <EFBFBD>в<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %s", _larr + 1, _fstr);
continue; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD>
}
_model->array[_larr++] = value;
_model->realength++;
if(_model -> maxlength >= 73728 && (_larr >= (_model -> maxlength/10)*_times)){
progress = _larr >= _model -> maxlength ? 100 : _times++ == 0 ? 0 : progress + 10;
DEBUG_PRINTF("\r\n[");
for(u16 j=0; j<50;j++){
if(j < progress/2) DEBUG_PRINTF("=");
else DEBUG_PRINTF(" ");
printf("\r\n[");
for(uint16_t j=0; j<50;j++){
if(j < progress/2) printf("=");
else printf(" ");
}
DEBUG_PRINTF("] %d%%", progress);
printf("] %d%%", progress);
}
if(_larr >= _model -> maxlength)break;
}
DEBUG_PRINTF("\r\n模型参数[%s]已写入到内存中! 模型长度为 %d\r\n",_model -> dname ? _model -> dname : _model -> name,_model -> realength);
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 0;
}
return 1;
@@ -240,7 +239,7 @@ u8 model_write(char* model_name)
u8 model_read(char* model_name, u32 start, u32 end, u32 gap){
uint8_t model_read(char* model_name, uint32_t start, uint32_t end, uint32_t gap){
if(strcmp(model_name, "all") == 0){
model_read("conv1_bias", start, end, gap);
model_read("conv1_weight", start, end, gap);
@@ -257,7 +256,7 @@ u8 model_read(char* model_name, u32 start, u32 end, u32 gap){
Model *_model = model(model_name);
if(_model == NULL || end == 0 || start > _model -> realength || end > _model -> realength)return 0;
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)
for (uint32_t 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;
@@ -268,30 +267,30 @@ u8 model_read(char* model_name, u32 start, u32 end, u32 gap){
u8 model_switchdata(char* data_name){
u8 _len = strlen(data_name);
uint8_t model_switchdata(char* data_name){
uint8_t _len = strlen(data_name);
char _path[_len+1+7];
if(data.array != NULL)modelmym_free("data");
sprintf(_path, "./dataset/_data/%s.txt", data_name);
FILE *file = fopen(_path, "r");
if(file == NULL){
DEBUG_PRINTF("\r\nData数据集[%s]不存在\r\n",data_name);
printf("\r\nData<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>[%s]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n",data_name);
return 0;
}else{
u8 _res = model_write(data_name);
uint8_t _res = model_write(data_name);
if (_res) {
DEBUG_PRINTF("Data数据集[%s]切换失败!!\r\n",data_name);
printf("Data<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>[%s]<5D>л<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>\r\n",data_name);
return 0;
}
else DEBUG_PRINTF("Data数据集[%s]切换成功!\r\n",data_name);
DEBUG_PRINTF("data_name的长度为:%d\r\n_path的长度为:%d\r\n_path为:%s\r\n",_len,sizeof(_path),_path);
else printf("Data<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>[%s]<5D>л<EFBFBD><D0BB>ɹ<EFBFBD><C9B9><EFBFBD>\r\n",data_name);
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;
}
}
u8 model_info(char* model_name){
uint8_t model_info(char* model_name){
if(strcmp(model_name, "all") == 0){
model_info("conv1_bias");
model_info("conv1_weight");
@@ -311,7 +310,7 @@ u8 model_info(char* 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); 这函数有BUGmodel_dataset函数
//if(strcmp(_model -> name, "data") == 0)printf("dataset is: %s\r\n",_model -> dname); <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BUG<EFBFBD><EFBFBD><EFBFBD><EFBFBD>model_dataset<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return 1;
}
return 0;
@@ -346,7 +345,7 @@ void model_init(){
conv1_weight.array = modelmym_init(conv1_weight.name);
conv1_weight.maxlength = CONV1_WEIGHT_ARRSIZE;
conv1_weight.channel = 1;
conv1_weight.num_kernels = 32;
conv1_weight.num_kernels = CONV1_BIAS_ARRSIZE;
conv2_bias.name = "conv2_bias";
conv2_bias.array = modelmym_init(conv2_bias.name);
@@ -356,7 +355,7 @@ void model_init(){
conv2_weight.array = modelmym_init(conv2_weight.name);
conv2_weight.maxlength = CONV2_WEIGHT_ARRSIZE;
conv2_weight.channel = 32;
conv2_weight.num_kernels = 64;
conv2_weight.num_kernels = CONV2_BIAS_ARRSIZE;
conv3_bias.name = "conv3_bias";
conv3_bias.array = modelmym_init(conv3_bias.name);
@@ -366,7 +365,7 @@ void model_init(){
conv3_weight.array = modelmym_init(conv3_weight.name);
conv3_weight.maxlength = CONV3_WEIGHT_ARRSIZE;
conv3_weight.channel = 64;
conv3_weight.num_kernels = 128;
conv3_weight.num_kernels = CONV3_BIAS_ARRSIZE;
fc1_bias.name = "fc1_bias";
fc1_bias.array = modelmym_init(fc1_bias.name);
@@ -383,7 +382,7 @@ void model_init(){
fc2_weight.name = "fc2_weight";
fc2_weight.array = modelmym_init(fc2_weight.name);
fc2_weight.maxlength = FC2_WEIGHT_ARRSIZE;
fc2_weight.num_kernels = FC2_WEIGHT_KERNELS;
fc2_weight.num_kernels = FC2_BIAS_ARRSIZE;
data.name = "data";
data.array = modelmym_init(data.name);