save
This commit is contained in:
@@ -169,13 +169,14 @@ float* hidden(const float* input_matrix){
|
||||
return affine1_rslt;
|
||||
}
|
||||
|
||||
float* output(const float* input_matrix){
|
||||
float* output(Model model_w, const float* input_matrix){
|
||||
u8 num = model_w.num_kernels;
|
||||
float affine2_temp; // <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ洢<DAB4><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
float *affine2_rslt = (float *) mymalloc(SRAMEX,sizeof(float)*7);
|
||||
memset(affine2_rslt, 0, sizeof(float)*7);
|
||||
float *affine2_rslt = (float *) mymalloc(SRAMEX,(sizeof(float)*num));
|
||||
memset(affine2_rslt, 0, sizeof(float)*num);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>10<31><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10<31><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for(int n=0; n<7; n++)
|
||||
for(int n=0; n<num; n++)
|
||||
{
|
||||
affine2_temp = 0; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>Ϊ0
|
||||
|
||||
@@ -256,10 +257,10 @@ float* generateMatrix(Model model, const float* value)
|
||||
return CNN_data;
|
||||
}
|
||||
|
||||
float calculate_probabilities(float *input_array)
|
||||
float calculate_probabilities(Model model_w, float *input_array)
|
||||
{
|
||||
float sum = 0;
|
||||
u8 input_num = 7;
|
||||
u8 input_num = model_w.num_kernels;
|
||||
float *result = (float *) mymalloc(SRAMEX,sizeof(float)*input_num);
|
||||
memset(result, 0, sizeof(float)*input_num);
|
||||
|
||||
@@ -297,8 +298,8 @@ float calculate_probabilities(float *input_array)
|
||||
}
|
||||
|
||||
|
||||
u8 calculate_layer(float *input_array){
|
||||
u8 input_num = 7;
|
||||
u8 calculate_layer(Model model_w, float *input_array){
|
||||
u8 input_num = model_w.num_kernels;
|
||||
u8 predict_num = 0;
|
||||
float max_temp = -100;
|
||||
for(int n=0; n<input_num; n++)
|
||||
@@ -309,8 +310,8 @@ u8 calculate_layer(float *input_array){
|
||||
predict_num = n; // <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
//print_rslt(input_array,7,7);
|
||||
return predict_num+1;
|
||||
print_rslt(input_array,input_num,input_num);
|
||||
return predict_num+0;
|
||||
}
|
||||
|
||||
|
||||
@@ -320,9 +321,14 @@ void cnn_run(){
|
||||
if (check_threshold(data,&value[0])){
|
||||
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>100 * 100 <20><><EFBFBD><EFBFBD>
|
||||
float* _data = generateMatrix(data,&value[0]);
|
||||
char kind[50];
|
||||
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ磡<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ:%f ƽ<><C6BD>ֵ:%f <20><><EFBFBD><D7BC>:%f\r\n",value[0],value[1],value[2]);
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD>ԭʼ<EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD>SD<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n");
|
||||
|
||||
SDRAM_TO_SD();
|
||||
char* _uuid = uuid();
|
||||
CSTX_4G_RegALiYunIOT(1); //<2F><><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>ģ<EFBFBD><C4A3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ϱ<EFBFBD>
|
||||
send_blocks(_data,_uuid);
|
||||
|
||||
//<2F><>һ<EFBFBD>㣺<EFBFBD><E3A3BA><EFBFBD><EFBFBD>102 * 102
|
||||
@@ -367,10 +373,15 @@ void cnn_run(){
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD><EFBFBD>IJ㿪ʼ\n");
|
||||
float* affine1_rslt = hidden(pool_rslt_3);
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㿪ʼ\r\n");
|
||||
float* affine2_rslt = output(affine1_rslt);
|
||||
float* affine2_rslt = output(fc2_weight, affine1_rslt);
|
||||
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>%f\n",calculate_probabilities(affine2_rslt));
|
||||
printf("Label is:%d\r\n",calculate_layer(affine2_rslt));
|
||||
DEBUG_PRINTF("<EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>%f\r\n",calculate_probabilities(fc2_weight, affine2_rslt));
|
||||
DEBUG_PRINTF("Label is:%d\r\n",calculate_layer(fc2_weight, affine2_rslt));
|
||||
|
||||
snprintf(kind, 50,"UUID:%s P:%f Label:%d", _uuid, calculate_probabilities(fc2_weight, affine2_rslt), calculate_layer(fc2_weight, affine2_rslt));
|
||||
CSTX_4G_ALiYunIOTSenddata_string(kind,"kind_string");
|
||||
|
||||
CSTX_4G_RegALiYunIOT(0); //<2F><><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD>ʱ<EFBFBD><CAB1> <20>ź<EFBFBD>
|
||||
|
||||
myfree(SRAMEX,pool_rslt_3);
|
||||
pool_rslt_3 = NULL;
|
||||
@@ -378,7 +389,7 @@ void cnn_run(){
|
||||
affine1_rslt = NULL;
|
||||
myfree(SRAMEX,affine2_rslt);
|
||||
affine2_rslt = NULL;
|
||||
|
||||
|
||||
} else{
|
||||
DEBUG_PRINTF("δ<EFBFBD>ŵ磡<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ:%f ƽ<><C6BD>ֵ:%f <20><><EFBFBD><D7BC>:%f\r\n",value[0],value[1],value[2]);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "tools.h"
|
||||
#include "Function.h"
|
||||
|
||||
void cnn_run(void);
|
||||
void _cnn_run(void);
|
||||
|
||||
@@ -14,7 +14,7 @@ Model fc2_bias;
|
||||
Model fc2_weight;
|
||||
Model data;
|
||||
|
||||
|
||||
float data_array[DATA_ARRSIZE] __attribute__((at(0XC0009C40)));
|
||||
|
||||
float* modelmym_init(char* model_name){
|
||||
if(conv1_bias.array == NULL && strcmp(model_name, "conv1_bias") == 0)
|
||||
@@ -37,8 +37,8 @@ float* modelmym_init(char* model_name){
|
||||
return fc2_bias.array = (float*)mymalloc(SRAMEX, FC2_BIAS_ARRSIZE * sizeof(float));
|
||||
else if(fc2_weight.array == NULL && strcmp(model_name, "fc2_weight") == 0)
|
||||
return fc2_weight.array = (float*)mymalloc(SRAMEX, FC2_WEIGHT_ARRSIZE * sizeof(float));
|
||||
else if(data.array == NULL && strcmp(model_name, "data") == 0)
|
||||
return data.array = (float*)mymalloc(SRAMEX, DATA_ARRSIZE * sizeof(float));
|
||||
// else if(data.array == NULL && strcmp(model_name, "data") == 0)
|
||||
// return data.array = (float*)mymalloc(SRAMEX, DATA_ARRSIZE * sizeof(float));
|
||||
else if(strcmp(model_name, "all") == 0){
|
||||
if(conv1_bias.array == NULL)conv1_bias.array = (float*)mymalloc(SRAMEX, CONV1_BIAS_ARRSIZE * sizeof(float));
|
||||
if(conv1_weight.array == NULL)conv1_weight.array = (float*)mymalloc(SRAMEX, CONV1_WEIGHT_ARRSIZE * sizeof(float));
|
||||
@@ -50,7 +50,7 @@ float* modelmym_init(char* model_name){
|
||||
if(fc1_weight.array == NULL)fc1_weight.array = (float*)mymalloc(SRAMEX, FC1_WEIGHT_ARRSIZE * sizeof(float));
|
||||
if(fc2_bias.array == NULL)fc2_bias.array = (float*)mymalloc(SRAMEX, FC2_BIAS_ARRSIZE * sizeof(float));
|
||||
if(fc2_weight.array == NULL)fc2_weight.array = (float*)mymalloc(SRAMEX, FC2_WEIGHT_ARRSIZE * sizeof(float));
|
||||
if(data.array == NULL)data.array = (float*)mymalloc(SRAMEX, DATA_ARRSIZE * sizeof(float));
|
||||
// if(data.array == NULL)data.array = (float*)mymalloc(SRAMEX, DATA_ARRSIZE * sizeof(float));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -119,9 +119,9 @@ u8 modelmym_free(char* model_name){
|
||||
return 1;
|
||||
}
|
||||
else if(data.array != NULL && strcmp(model_name, "data") == 0){
|
||||
myfree(SRAMEX,data.array);
|
||||
data.array = NULL;
|
||||
data.realength = 0;
|
||||
// myfree(SRAMEX,data.array);
|
||||
memset(data.array, 0 ,data.maxlength);
|
||||
// data.realength = 0;
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(model_name, "all") == 0){
|
||||
@@ -173,7 +173,7 @@ u8 model_write(char* model_name)
|
||||
Model *_model = model(model_name);
|
||||
|
||||
if(_model == NULL || strcmp(model_name, "data") == 0){
|
||||
sprintf(_path, "0:/dataset/_data/%s.txt", model_name);
|
||||
sprintf(_path, "dataset/_data/%s.txt", model_name);
|
||||
if(f_open(file, (const TCHAR *)_path, 1)){
|
||||
DEBUG_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;
|
||||
@@ -184,7 +184,7 @@ u8 model_write(char* model_name)
|
||||
}
|
||||
|
||||
if(_model -> dname == NULL){
|
||||
sprintf(_path, "0:/dataset/%s.txt", _model -> name);
|
||||
sprintf(_path, "dataset/%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>[%s]\r\n", _path);
|
||||
return 4;
|
||||
@@ -197,7 +197,7 @@ u8 model_write(char* model_name)
|
||||
}
|
||||
|
||||
if(_model -> dname)sprintf(_datapath, "_data/%s", _model -> dname);
|
||||
sprintf(_path, "0:/dataset/%s.txt", _model -> dname ? _datapath : _model -> name);
|
||||
sprintf(_path, "dataset/%s.txt", _model -> dname ? _datapath : _model -> name);
|
||||
if(f_open(file, (const TCHAR *)_path, 1)){
|
||||
DEBUG_PRINTF("<EFBFBD>ļ<EFBFBD>[%s]<5D><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>\r\n", _model -> dname ? _model -> dname : _model -> name);
|
||||
return 199;
|
||||
@@ -286,7 +286,7 @@ u8 model_switchdata(char* data_name){
|
||||
u8 _len = strlen(data_name);
|
||||
char _path[_len+1+7+35];
|
||||
if(data.array != NULL)modelmym_free("data");
|
||||
sprintf(_path, "0:/dataset/_data/%s.txt",data_name);
|
||||
sprintf(_path, "dataset/_data/%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 0;
|
||||
@@ -361,7 +361,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);
|
||||
@@ -371,7 +371,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);
|
||||
@@ -381,7 +381,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);
|
||||
@@ -398,10 +398,14 @@ 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_BIAS_ARRSIZE;
|
||||
|
||||
data.name = "data";
|
||||
data.array = modelmym_init(data.name);
|
||||
data.array = data_array;
|
||||
data.maxlength = DATA_ARRSIZE;
|
||||
data.realength = DATA_ARRSIZE;
|
||||
data.dname = "data";
|
||||
|
||||
memset(data.array, 0, sizeof(float)*DATA_ARRSIZE);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,15 +36,12 @@ typedef struct {
|
||||
#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 is1250000 1
|
||||
#if is1250000
|
||||
#define DATA_ARRSIZE (1250000)
|
||||
#else
|
||||
#define DATA_ARRSIZE (100 * 100)
|
||||
#endif
|
||||
|
||||
|
||||
#define FC2_BIAS_ARRSIZE (4) //4<><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define FC2_WEIGHT_ARRSIZE (4*128)
|
||||
#define DATA_ARRSIZE (1300000) //ԭʼ<D4AD><CABC><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> 1300000
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -100,6 +100,6 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
if(htim==(&TIM3_Handler))
|
||||
{
|
||||
LED1=!LED1; //LED1<44><31>ת
|
||||
LED_R=!LED_R; //LED1<44><31>ת
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ void send_blocks(float* arr, char* uuid_str){
|
||||
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) {
|
||||
if (block_index >= 7000) {
|
||||
block_index = 0; // <20><><EFBFBD>ÿ<EFBFBD>
|
||||
_total_len++;
|
||||
}
|
||||
@@ -39,13 +39,15 @@ void send_blocks(float* arr, char* uuid_str){
|
||||
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) {
|
||||
if (block_index >= 7000) {
|
||||
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);
|
||||
DEBUG_PRINTF("%s", _block);
|
||||
myfree(SRAMEX,_block);
|
||||
sprintf(_block, "{\\\"uuid\\\":\\\"%s\\\",\\\"Bid\\\":\\\"%d\\\",\\\"Eid\\\":\\\"%d\\\",\\\"Block\\\":\\\"%s\\\"}\n", uuid_str, total_len++, _total_len, block);
|
||||
//DEBUG_PRINTF("%s", _block);
|
||||
|
||||
CSTX_4G_ALiYunIOTSenddata_string(_block,"data_string");
|
||||
myfree(SRAMEX,_block);
|
||||
_block = NULL;
|
||||
}
|
||||
}
|
||||
@@ -56,13 +58,13 @@ void send_blocks(float* arr, char* uuid_str){
|
||||
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);
|
||||
DEBUG_PRINTF("%s", _block);
|
||||
myfree(SRAMEX,_block);
|
||||
sprintf(_block, "{\\\"uuid\\\":\\\"%s\\\",\\\"Bid\\\":\\\"%d\\\",\\\"Eid\\\":\\\"%d\\\",\\\"Block\\\":\\\"%s\\\"}\n", uuid_str, total_len, _total_len, block);
|
||||
//DEBUG_PRINTF("%s", _block);
|
||||
CSTX_4G_ALiYunIOTSenddata_string(_block,"data_string");
|
||||
myfree(SRAMEX,_block);
|
||||
_block = NULL;
|
||||
}
|
||||
|
||||
myfree(SRAMEX,block);
|
||||
block = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "cnn_model.h"
|
||||
#include "debug.h"
|
||||
#include "EC800M.h"
|
||||
|
||||
|
||||
char* uuid(void);
|
||||
|
||||
Reference in New Issue
Block a user