diff --git a/src/cnn/creation.c b/src/cnn/creation.c index 7a004ef..582a224 100644 --- a/src/cnn/creation.c +++ b/src/cnn/creation.c @@ -29,7 +29,9 @@ Network* create_network(int max_size, int learning_rate, int dropout, int initia network->kernel[0]->nn = NULL; network->kernel[0]->cnn = NULL; create_a_cube_input_layer(network, 0, input_depth, input_dim); - create_a_cube_input_z_layer(network, 0, input_depth, input_dim); + // create_a_cube_input_z_layer(network, 0, input_depth, input_dim); + // This shouldn't be used (if I'm not mistaken) so to save space, we can do: + ntework->input_z[0] = NULL; // As we don't backpropagate the input return network; } @@ -104,7 +106,7 @@ void add_2d_average_pooling(Network* network, int dim_output) { network->kernel[k_pos]->nn = NULL; network->kernel[k_pos]->activation = 100*kernel_size; // Ne contient pas de fonction d'activation create_a_cube_input_layer(network, n, network->depth[n-1], network->width[n-1]/2); - create_a_cube_input_z_layer(network, n, network->depth[n-1], network->width[n-1]/2); + create_a_cube_input_z_layer(network, n, network->depth[n-1], network->width[n-1]/2); // Will it be used ? network->size++; } @@ -130,33 +132,26 @@ void add_convolution(Network* network, int depth_output, int dim_output, int act cnn->columns = depth_output; cnn->w = (float****)malloc(sizeof(float***)*depth_input); cnn->d_w = (float****)malloc(sizeof(float***)*depth_input); - cnn->last_d_w = (float****)malloc(sizeof(float***)*depth_input); for (int i=0; i < depth_input; i++) { cnn->w[i] = (float***)malloc(sizeof(float**)*depth_output); cnn->d_w[i] = (float***)malloc(sizeof(float**)*depth_output); - cnn->last_d_w[i] = (float***)malloc(sizeof(float**)*depth_output); for (int j=0; j < depth_output; j++) { cnn->w[i][j] = (float**)malloc(sizeof(float*)*kernel_size); cnn->d_w[i][j] = (float**)malloc(sizeof(float*)*kernel_size); - cnn->last_d_w[i][j] = (float**)malloc(sizeof(float*)*kernel_size); for (int k=0; k < kernel_size; k++) { cnn->w[i][j][k] = (float*)malloc(sizeof(float)*kernel_size); cnn->d_w[i][j][k] = (float*)malloc(sizeof(float)*kernel_size); - cnn->last_d_w[i][j][k] = (float*)malloc(sizeof(float)*kernel_size); } } } cnn->bias = (float***)malloc(sizeof(float**)*depth_output); cnn->d_bias = (float***)malloc(sizeof(float**)*depth_output); - cnn->last_d_bias = (float***)malloc(sizeof(float**)*depth_output); for (int i=0; i < depth_output; i++) { cnn->bias[i] = (float**)malloc(sizeof(float*)*bias_size); cnn->d_bias[i] = (float**)malloc(sizeof(float*)*bias_size); - cnn->last_d_bias[i] = (float**)malloc(sizeof(float*)*bias_size); for (int j=0; j < bias_size; j++) { cnn->bias[i][j] = (float*)malloc(sizeof(float)*bias_size); cnn->d_bias[i][j] = (float*)malloc(sizeof(float)*bias_size); - cnn->last_d_bias[i][j] = (float*)malloc(sizeof(float)*bias_size); } } create_a_cube_input_layer(network, n, depth_output, bias_size); @@ -188,14 +183,11 @@ void add_dense(Network* network, int output_units, int activation) { nn->output_units = output_units; nn->bias = (float*)malloc(sizeof(float)*output_units); nn->d_bias = (float*)malloc(sizeof(float)*output_units); - nn->last_d_bias = (float*)malloc(sizeof(float)*output_units); nn->weights = (float**)malloc(sizeof(float*)*input_units); nn->d_weights = (float**)malloc(sizeof(float*)*input_units); - nn->last_d_weights = (float**)malloc(sizeof(float*)*input_units); for (int i=0; i < input_units; i++) { nn->weights[i] = (float*)malloc(sizeof(float)*output_units); nn->d_weights[i] = (float*)malloc(sizeof(float)*output_units); - nn->last_d_weights[i] = (float*)malloc(sizeof(float)*output_units); } create_a_line_input_layer(network, n, output_units); create_a_line_input_z_layer(network, n, output_units); @@ -227,14 +219,11 @@ void add_dense_linearisation(Network* network, int output_units, int activation) nn->bias = (float*)malloc(sizeof(float)*output_units); nn->d_bias = (float*)malloc(sizeof(float)*output_units); - nn->last_d_bias = (float*)malloc(sizeof(float)*output_units); nn->weights = (float**)malloc(sizeof(float*)*input_units); nn->d_weights = (float**)malloc(sizeof(float*)*input_units); - nn->last_d_weights = (float**)malloc(sizeof(float*)*input_units); for (int i=0; i < input_units; i++) { nn->weights[i] = (float*)malloc(sizeof(float)*output_units); nn->d_weights[i] = (float*)malloc(sizeof(float)*output_units); - nn->last_d_weights[i] = (float*)malloc(sizeof(float)*output_units); } /* Not currently used initialisation_1d_matrix(network->initialisation, nn->bias, output_units, output_units+input_units); diff --git a/src/cnn/free.c b/src/cnn/free.c index c4092b6..445572e 100644 --- a/src/cnn/free.c +++ b/src/cnn/free.c @@ -40,34 +40,27 @@ void free_convolution(Network* network, int pos) { for (int j=0; j < bias_size; j++) { free(k_pos->bias[i][j]); free(k_pos->d_bias[i][j]); - free(k_pos->last_d_bias[i][j]); } free(k_pos->bias[i]); free(k_pos->d_bias[i]); - free(k_pos->last_d_bias[i]); } free(k_pos->bias); free(k_pos->d_bias); - free(k_pos->last_d_bias); for (int i=0; i < r; i++) { for (int j=0; j < c; j++) { for (int k=0; k < k_size; k++) { free(k_pos->w[i][j][k]); free(k_pos->d_w[i][j][k]); - free(k_pos->last_d_w[i][j][k]); } free(k_pos->w[i][j]); free(k_pos->d_w[i][j]); - free(k_pos->last_d_w[i][j]); } free(k_pos->w[i]); free(k_pos->d_w[i]); - free(k_pos->last_d_w[i]); } free(k_pos->w); free(k_pos->d_w); - free(k_pos->last_d_w); free(k_pos); } @@ -79,15 +72,12 @@ void free_dense(Network* network, int pos) { for (int i=0; i < dim; i++) { free(k_pos->weights[i]); free(k_pos->d_weights[i]); - free(k_pos->last_d_weights[i]); } free(k_pos->weights); free(k_pos->d_weights); - free(k_pos->last_d_weights); free(k_pos->bias); free(k_pos->d_bias); - free(k_pos->last_d_bias); free(k_pos); } @@ -99,15 +89,12 @@ void free_dense_linearisation(Network* network, int pos) { for (int i=0; i < dim; i++) { free(k_pos->weights[i]); free(k_pos->d_weights[i]); - free(k_pos->last_d_weights[i]); } free(k_pos->weights); free(k_pos->d_weights); - free(k_pos->last_d_weights); free(k_pos->bias); free(k_pos->d_bias); - free(k_pos->last_d_bias); free(k_pos); } diff --git a/src/cnn/include/function.h b/src/cnn/include/function.h index a3fdcf8..344edb2 100644 --- a/src/cnn/include/function.h +++ b/src/cnn/include/function.h @@ -48,6 +48,9 @@ void choose_apply_function_matrix(int activation, float*** input, int depth, int */ void choose_apply_function_vector(int activation, float*** input, int dim); +/* +* Renvoie la fonction d'activation correspondant à son identifiant (activation) +*/ ptr get_function_activation(int activation); #endif \ No newline at end of file diff --git a/src/cnn/include/struct.h b/src/cnn/include/struct.h index d630e3a..d8c6224 100644 --- a/src/cnn/include/struct.h +++ b/src/cnn/include/struct.h @@ -7,10 +7,8 @@ typedef struct Kernel_cnn { int columns; // Depth of the output float*** bias; // bias[columns][dim_output][dim_output] float*** d_bias; // d_bias[columns][dim_output][dim_output] - float*** last_d_bias; // last_d_bias[columns][dim_output][dim_output] float**** w; // w[rows][columns][k_size][k_size] float**** d_w; // d_w[rows][columns][k_size][k_size] - float**** last_d_w; // last_d_w[rows][columns][k_size][k_size] } Kernel_cnn; typedef struct Kernel_nn { @@ -18,10 +16,8 @@ typedef struct Kernel_nn { int output_units; // Nombre d'éléments en sortie float* bias; // bias[output_units] float* d_bias; // d_bias[output_units] - float* last_d_bias; // last_d_bias[output_units] float** weights; // weight[input_units][output_units] float** d_weights; // d_weights[input_units][output_units] - float** last_d_weights; // last_d_weights[input_units][output_units] } Kernel_nn; typedef struct Kernel { diff --git a/test/cnn_convolution.cu b/test/cnn_convolution.cu index f092431..28c863d 100644 --- a/test/cnn_convolution.cu +++ b/test/cnn_convolution.cu @@ -104,16 +104,13 @@ void run_convolution_test(int input_dim, int output_dim, int rows, int columns) // bias[kernel->columns][dim_output][dim_output] kernel->bias = create_matrix(kernel->columns, output_dim, output_dim, 15.0f); kernel->d_bias = create_matrix(kernel->columns, output_dim, output_dim, 1.5f); - kernel->last_d_bias = create_matrix(kernel->columns, output_dim, output_dim, 0.1f); // w[rows][columns][k_size][k_size] kernel->w = (float****)malloc(sizeof(float***)*kernel->rows); kernel->d_w = (float****)malloc(sizeof(float***)*kernel->rows); - kernel->last_d_w = (float****)malloc(sizeof(float***)*kernel->rows); for (int i=0; i < kernel->rows; i++) { kernel->w[i] = create_matrix(kernel->columns, kernel->k_size, kernel->k_size, 15.0f); kernel->d_w[i] = create_matrix(kernel->columns, kernel->k_size, kernel->k_size, 1.5f); - kernel->last_d_w[i] = create_matrix(kernel->columns, kernel->k_size, kernel->k_size, 0.1f); } float*** input = create_matrix(kernel->rows, input_dim, input_dim, 5.0f); @@ -151,16 +148,13 @@ void run_convolution_test(int input_dim, int output_dim, int rows, int columns) free_matrix(kernel->bias, kernel->columns, output_dim); free_matrix(kernel->d_bias, kernel->columns, output_dim); - free_matrix(kernel->last_d_bias, kernel->columns, output_dim); for (int i=0; i < kernel->rows; i++) { free_matrix(kernel->w[i], kernel->columns, kernel->k_size); free_matrix(kernel->d_w[i], kernel->columns, kernel->k_size); - free_matrix(kernel->last_d_w[i], kernel->columns, kernel->k_size); } free(kernel->w); free(kernel->d_w); - free(kernel->last_d_w); free_matrix(input, kernel->rows, input_dim); free_matrix(output_cpu, kernel->columns, output_dim);