From 0c49729e0ea8308716eecd02e6673c67f5946bc1 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Mon, 23 May 2022 17:27:38 +0200 Subject: [PATCH] Add free --- src/mnist/main.c | 9 +++++++-- src/mnist/neural_network.c | 2 ++ src/mnist/utils.c | 1 + test/neural_network.c | 1 + test/neuron_io.c | 3 +++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/mnist/main.c b/src/mnist/main.c index 785b4d2..f39be5a 100644 --- a/src/mnist/main.c +++ b/src/mnist/main.c @@ -249,7 +249,7 @@ float** recognize(char* modele, char* entree) { } } deletion_of_network(network); - + free(parameters); return results; } @@ -283,6 +283,7 @@ void print_recognize(char* modele, char* entree, char* sortie) { } else printf("Probabilité %d: %f\n", j, resultats[i][j]); } + free(resultats[i]); if (! strcmp(sortie, "json")) { if (i+1 < nb_images) { printf("],\n"); @@ -291,10 +292,11 @@ void print_recognize(char* modele, char* entree, char* sortie) { } } } + free(resultats); + free(parameters); if (! strcmp(sortie, "json")) { printf("}\n"); } - } void test(char* modele, char* fichier_images, char* fichier_labels, bool preview_fails) { @@ -320,8 +322,11 @@ void test(char* modele, char* fichier_images, char* fichier_labels, bool preview printf("--- Image %d, %d --- Prévision: %d ---\n", i, labels[i], indice_max(resultats[i], nb_last_layer)); print_image(width, height, images[i], resultats[i]); } + free(resultats[i]); } printf("%d Images\tAccuracy: %0.1f%%\n", nb_images, accuracy*100); + free(parameters); + free(resultats); } diff --git a/src/mnist/neural_network.c b/src/mnist/neural_network.c index bd255a2..f802dcd 100644 --- a/src/mnist/neural_network.c +++ b/src/mnist/neural_network.c @@ -89,9 +89,11 @@ void deletion_of_network(Network* network) { free(neuron->weights); free(neuron->back_weights); free(neuron->last_back_weights); + free(neuron); } } free(layer->neurons); // On libère enfin la liste des neurones de la couche + free(network->layers[i]); } free(network->layers); free(network); // Pour finir, on libère le réseau neuronal contenant la liste des couches diff --git a/src/mnist/utils.c b/src/mnist/utils.c index ca68de4..650edf1 100644 --- a/src/mnist/utils.c +++ b/src/mnist/utils.c @@ -75,6 +75,7 @@ void count_labels(char* filename) { for (int i=0; i < 10; i++) { printf("Nombre de %d: %x\n", i, tab[i]); } + free(labels); } void create_network(char* filename, int sortie) { diff --git a/test/neural_network.c b/test/neural_network.c index f22625b..ae7583a 100644 --- a/test/neural_network.c +++ b/test/neural_network.c @@ -24,5 +24,6 @@ int main() { write_network(".test-cache/random_network.bin", network); printf("OK\n"); + deletion_of_network(network); return 0; } \ No newline at end of file diff --git a/test/neuron_io.c b/test/neuron_io.c index d7817eb..1fc586f 100644 --- a/test/neuron_io.c +++ b/test/neuron_io.c @@ -4,6 +4,7 @@ #include #include "../src/mnist/neuron_io.c" +#include "../src/mnist/neural_network.c" Neuron* creer_neuron(int nb_sortants) { @@ -70,5 +71,7 @@ int main() { printf("Vérification de l'accès en lecture\n"); Network* network2 = read_network(".test-cache/neuron_io.bin"); printf("OK\n"); + deletion_of_network(network); + deletion_of_network(network2); return 0; } \ No newline at end of file