mirror of
https://github.com/augustin64/projet-tipe
synced 2025-02-02 19:39:39 +01:00
Fix various memory leaks in mnist NN
This commit is contained in:
parent
48dcded57a
commit
dd6fb046c7
@ -248,6 +248,16 @@ void train(int epochs, int layers, int neurons, char* recovery, char* image_file
|
||||
for (int j=0; j < nb_threads; j++) {
|
||||
free(train_parameters[j]);
|
||||
}
|
||||
|
||||
for (int i=0; i < nb_images_total; i++) {
|
||||
for (int j=0; j < height; j++) {
|
||||
free(images[i][j]);
|
||||
}
|
||||
free(images[i]);
|
||||
}
|
||||
free(images);
|
||||
free(labels);
|
||||
|
||||
free(shuffle_indices);
|
||||
free(train_parameters);
|
||||
// On libère les espaces mémoire utilisés spécialement sur le CPU
|
||||
|
@ -84,14 +84,15 @@ void deletion_of_network(Network* network) {
|
||||
|
||||
for (int i=0; i < network->nb_layers; i++) {
|
||||
layer = network->layers[i];
|
||||
if (i != network->nb_layers-1) { // On exclut la dernière couche dont les neurones ne contiennent pas de poids sortants
|
||||
|
||||
for (int j=0; j < network->layers[i]->nb_neurons; j++) {
|
||||
neuron = layer->neurons[j];
|
||||
if (i != network->nb_layers-1) { // On exclut la dernière couche dont les neurones ne contiennent pas de poids sortants
|
||||
free(neuron->weights);
|
||||
free(neuron->back_weights);
|
||||
free(neuron->last_back_weights);
|
||||
free(neuron);
|
||||
}
|
||||
free(neuron);
|
||||
}
|
||||
free(layer->neurons);
|
||||
free(network->layers[i]);
|
||||
|
@ -24,6 +24,7 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
|
||||
neuron->last_back_bias = 0.0;
|
||||
neuron->back_bias = 0.0;
|
||||
|
||||
if (nb_weights != 0) {
|
||||
neuron->last_back_weights = (float*)malloc(sizeof(float)*nb_weights);
|
||||
neuron->back_weights = (float*)malloc(sizeof(float)*nb_weights);
|
||||
neuron->weights = (float*)malloc(sizeof(float)*nb_weights);
|
||||
@ -34,6 +35,7 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
|
||||
neuron->back_weights[i] = 0.0;
|
||||
neuron->last_back_weights[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
return neuron;
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ void create_network(char* filename, int sortie) {
|
||||
|
||||
neuron->back_bias = 0.;
|
||||
neuron->last_back_bias = 0.;
|
||||
if (i != network->nb_layers-1) {
|
||||
neuron->weights = (float*)malloc(sizeof(float)*neurons_per_layer[i+1]);
|
||||
neuron->back_weights = (float*)malloc(sizeof(float)*neurons_per_layer[i+1]);
|
||||
neuron->last_back_weights = (float*)malloc(sizeof(float)*neurons_per_layer[i+1]);
|
||||
@ -109,6 +110,7 @@ void create_network(char* filename, int sortie) {
|
||||
neuron->back_weights[k] = 0.;
|
||||
neuron->last_back_weights[k] = 0.;
|
||||
}
|
||||
}
|
||||
layer->neurons[j] = neuron;
|
||||
}
|
||||
network->layers[i] = layer;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
Neuron* creer_neuron(int nb_sortants) {
|
||||
Neuron* neuron = (Neuron*)malloc(sizeof(Neuron));
|
||||
if (nb_sortants != 0) {
|
||||
neuron->weights = (float*)malloc(sizeof(float)*nb_sortants);
|
||||
neuron->back_weights = (float*)malloc(sizeof(float)*nb_sortants);
|
||||
neuron->last_back_weights = (float*)malloc(sizeof(float)*nb_sortants);
|
||||
@ -24,6 +25,7 @@ Neuron* creer_neuron(int nb_sortants) {
|
||||
neuron->bias = 0.0;
|
||||
neuron->back_bias = 0.0;
|
||||
neuron->last_back_bias = 0.0;
|
||||
}
|
||||
|
||||
return neuron;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user