From c948bd7c174c8d90d8094c162f582bc8be835c2f Mon Sep 17 00:00:00 2001 From: Qiea <1310371422@qq.com> Date: Mon, 11 Nov 2024 00:45:13 +0800 Subject: [PATCH] tmp --- cnn.c | 61 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/cnn.c b/cnn.c index caf79f5..49873a2 100644 --- a/cnn.c +++ b/cnn.c @@ -3,12 +3,12 @@ // 将原始矩阵复制到填充后的矩阵中央 -float* expand(const float* old_matrix, u8 old_matrix_length, u8 layer){ +float* expand(const float* old_matrix, int old_matrix_length, int layer){ float* new_matrix = (float *)malloc(sizeof(float)*layer*(old_matrix_length+2)*(old_matrix_length+2)); memset(new_matrix, 0, sizeof(float)*layer*(old_matrix_length+2)*(old_matrix_length+2)); - for(u8 l=0; l < layer; l++){ - for (u8 i = 0; i < old_matrix_length; i++) { - for (u8 j = 0; j < old_matrix_length; j++) { + for(int l=0; l < layer; l++){ + for (int i = 0; i < old_matrix_length; i++) { + for (int j = 0; j < old_matrix_length; j++) { new_matrix[(i + 1) * (old_matrix_length+2) + (j + 1) + l * (old_matrix_length+2) * (old_matrix_length+2)] = old_matrix[i * old_matrix_length + j + @@ -24,28 +24,33 @@ float* expand(const float* old_matrix, u8 old_matrix_length, u8 layer){ //input_matrix_length 输入图像的边长:102 //c_rl 输出图像的边长:100 //返回卷积的结果 -float* convolution(Model model_w, Model model_b, const float* input_matrix, u8 input_matrix_length){ +float* convolution(Model model_w, Model model_b, const float* input_matrix, int input_matrix_length){ // 初始化卷积层参数 - u8 im_l = input_matrix_length; - u8 cr_l = input_matrix_length - 2; + int _debug=0; + int im_l = input_matrix_length; + int cr_l = input_matrix_length - 2; float conv_temp; // 临时变量,用于存储卷积计算的中间结果 float* conv_rlst = (float *) malloc(sizeof (float) * model_w.num_kernels * (cr_l * cr_l)); memset(conv_rlst, 0, sizeof (float) * model_w.num_kernels * (cr_l * cr_l)); // 遍历30个卷积核(假设有30个通道) - for(u8 l=0;l