Add free_network

This commit is contained in:
Julien Chemillier 2022-10-05 11:10:13 +02:00
parent a29e8a2c0f
commit 75709589c2
2 changed files with 20 additions and 16 deletions

View File

@ -19,7 +19,7 @@ void free_a_line_input_layer(Network* network, int pos) {
} }
void free_2d_average_pooling(Network* network, int pos) { void free_2d_average_pooling(Network* network, int pos) {
free_a_cube_input_layer(network, pos+1, network->depth[pos-1], network->width[pos-1]/2); free_a_cube_input_layer(network, pos+1, network->depth[pos+1], network->width[pos+1]);
} }
void free_convolution(Network* network, int pos) { void free_convolution(Network* network, int pos) {
@ -27,8 +27,8 @@ void free_convolution(Network* network, int pos) {
int c = k_pos->columns; int c = k_pos->columns;
int k_size = k_pos->k_size; int k_size = k_pos->k_size;
int r = k_pos->rows; int r = k_pos->rows;
int bias_size = network->width[pos-1]-k_size+1; // Not sure of the value int bias_size = network->width[pos+1]; // Not sure of the value
free_a_cube_input_layer(network, pos+1, c, bias_size); free_a_cube_input_layer(network, pos+1, network->depth[pos+1], network->width[pos+1]);
for (int i=0; i < c; i++) { for (int i=0; i < c; i++) {
for (int j=0; j < bias_size; j++) { for (int j=0; j < bias_size; j++) {
free(k_pos->bias[i][j]); free(k_pos->bias[i][j]);
@ -104,16 +104,20 @@ void free_network_creation(Network* network) {
free(network); free(network);
} }
void free_network_lenet5(Network* network) { void free_network(Network* network) {
free_dense(network, 6); for (int i=network->size-2; i>=0; i--) {
free_dense(network, 5); if (network->kernel[i]->cnn != NULL) { // Convolution
free_dense_linearisation(network, 4); free_convolution(network, i);
free_average_pooling(network, 3); } else if (network->kernel[i]->nn != NULL) {
free_convolution(network, 2); if (network->depth[i]==1) { // Dense non linearised
free_average_pooling(network, 1); free_dense(network, i);
free_convolution(network, 0); } else { // Dense lineariation
free_network_creation(network); free_dense_linearisation(network, i);
if (network->size != network->max_size) { }
printf("033[33;1m[WARNING]\033[0m Le réseau LeNet5 est incomplet"); } else { // Pooling
free_2d_average_pooling(network, i);
}
} }
printf("Network freed successfully !\n");
free_network_creation(network);
} }

View File

@ -41,8 +41,8 @@ void free_dense_linearisation(Network* network, int pos);
void free_network_creation(Network* network); void free_network_creation(Network* network);
/* /*
* Libère l'espace mémoire alloué dans 'create_network_lenet5' (creation.c) * Libère l'espace mémoire alloué à un réseau quelconque
*/ */
void free_network_lenet5(Network* network); void free_network(Network* network);
#endif #endif