Deletion of last_d_bias and last_d_weights

This commit is contained in:
julienChemillier 2022-11-03 16:29:53 +01:00
parent 0e317549a5
commit df8d4f264e
5 changed files with 7 additions and 38 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -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 {

View File

@ -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);