diff --git a/cnn.c b/cnn.c index 95e3a57..ae7ceda 100644 --- a/cnn.c +++ b/cnn.c @@ -311,6 +311,7 @@ u8 calculate_layer(float *input_array){ void cnn_run(){ +#if is1250000 float value[3] = {0}; calculate_statistics(data,&value[0]); if (check_threshold(data,&value[0])){ @@ -368,4 +369,51 @@ void cnn_run(){ } else{ printf("未放电!最大值:%f 平均值:%f 标准差:%f\r\n",value[0],value[1],value[2]); } +#else + float* expand_matrix_1 = expand(data.array, 100, 1); + float* conv_rlst_1 = convolution(conv1_weight,conv1_bias,expand_matrix_1, 102); + float* pool_rslt_1 = pooling(conv1_weight, conv_rlst_1, 100); + + free(expand_matrix_1); + expand_matrix_1 = NULL; + free(conv_rlst_1); + conv_rlst_1 = NULL; + + //第二层:填充32 * 52 * 52 + float* expand_matrix_2 = expand(pool_rslt_1, 50, 32); + float* conv_rlst_2 = convolution(conv2_weight,conv2_bias,expand_matrix_2, 52); + float* pool_rslt_2 = pooling(conv2_weight, conv_rlst_2, 50); + + free(pool_rslt_1); + pool_rslt_1 = NULL; + free(expand_matrix_2); + expand_matrix_2 = NULL; + free(conv_rlst_2); + conv_rlst_2 = NULL; + + //第三层:填充 64 * 27 * 27 + float* expand_matrix_3 = expand(pool_rslt_2, 25, 64); + float* conv_rlst_3 = convolution(conv3_weight,conv3_bias,expand_matrix_3, 27); + float* pool_rslt_3 = pooling(conv3_weight, conv_rlst_3, 25); + + free(pool_rslt_2); + pool_rslt_2 = NULL; + free(expand_matrix_3); + expand_matrix_3 = NULL; + free(conv_rlst_3); + conv_rlst_3 = NULL; + + float* affine1_rslt = hidden(pool_rslt_3); + float* affine2_rslt = output(affine1_rslt); + + printf("概率:%f\r\n",calculate_probabilities(affine2_rslt)); + printf("Label is:%d\r\n",calculate_layer(affine2_rslt)); + + free(pool_rslt_3); + pool_rslt_3 = NULL; + free(affine1_rslt); + affine1_rslt = NULL; + free(affine2_rslt); + affine2_rslt = NULL; +#endif } diff --git a/cnn_model.h b/cnn_model.h index 0f57f68..8a0c8f3 100644 --- a/cnn_model.h +++ b/cnn_model.h @@ -34,7 +34,9 @@ typedef struct { #define FC1_WEIGHT_ARRSIZE (128*18432) //2359296 #define FC2_BIAS_ARRSIZE (7) #define FC2_WEIGHT_ARRSIZE (7*128) //896 -#if 1 + +#define is1250000 1 +#if is1250000 #define DATA_ARRSIZE (1250000) #else #define DATA_ARRSIZE (100 * 100) diff --git a/main.c b/main.c index 86870a5..51247e9 100644 --- a/main.c +++ b/main.c @@ -99,8 +99,10 @@ void run_dataset(){ int main(){ model_init(); model_write("all"); +// run_dataset(); - run_dataset(); + model_switchdata("C1autosave00095_right_new_2"); + cnn_run(); DEBUG_PRINTF("\r\nEnd结束"); }