Add loss information

This commit is contained in:
augustin64 2023-02-24 14:36:48 +01:00
parent e1fff4089b
commit 9b8aa1caf8
2 changed files with 13 additions and 3 deletions

View File

@ -19,6 +19,8 @@ void test_network_mnist(Network* network, char* images_file, char* labels_file,
int maxi; // Catégorie reconnue
int accuracy = 0; // Nombre d'images reconnues
float loss = 0.;
float* wanted_output;
// Load image
int* mnist_parameters = read_mnist_images_parameters(images_file);
@ -46,13 +48,18 @@ void test_network_mnist(Network* network, char* images_file, char* labels_file,
accuracy++;
}
// Compute loss
wanted_output = generate_wanted_output(labels[i], 10);
loss += compute_mean_squared_error(network->input[network->size-1][0][0], wanted_output, 10);
free(wanted_output);
for (int j=0; j < height; j++) {
free(images[i][j]);
}
free(images[i]);
}
free(images);
printf("%d Images. Taux de réussite: %.2f%%\n", nb_elem, 100*accuracy/(float)nb_elem);
printf("%d Images. Taux de réussite: %.2f%%\tLoss: %lf\n", nb_elem, 100*accuracy/(float)nb_elem, loss/nb_elem);
}

View File

@ -10,6 +10,7 @@
#include "../include/memory_management.h"
#include "../mnist/include/mnist.h"
#include "include/initialisation.h"
#include "include/test_network.h"
#include "include/neuron_io.h"
#include "../include/colors.h"
#include "../include/utils.h"
@ -326,15 +327,17 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
end_time = omp_get_wtime();
elapsed_time = end_time - start_time;
#ifdef USE_MULTITHREADING
printf("\rThreads [%d]\tÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: " GREEN "%0.4f%%" RESET " \tTemps: ", nb_threads, i, epochs, nb_images_total, nb_images_total, accuracy*100);
printf("\rThreads [%d]\tÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: " GREEN "%0.4f%%" RESET " \tLoss: %lf\tTemps: ", nb_threads, i, epochs, nb_images_total, nb_images_total, accuracy*100, loss);
printf_time(elapsed_time);
printf("\n");
#else
printf("\rÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: " GREEN "%0.4f%%" RESET " \tTemps: ", i, epochs, nb_images_total, nb_images_total, accuracy*100);
printf("\rÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: " GREEN "%0.4f%%" RESET " \tLoss: %lf\tTemps: ", i, epochs, nb_images_total, nb_images_total, accuracy*100, loss);
printf_time(elapsed_time);
printf("\n");
#endif
write_network(out, network);
// If you want to test the network between each epoch, uncomment the following line:
//test_network(0, out, "data/mnist/t10k-images-idx3-ubyte", "data/mnist/t10k-labels-idx1-ubyte", NULL, false);
}
// To generate a new neural and compare performances with scripts/benchmark_binary.py