From 577954908c9d5899e746d0167f9991118ed6ff0d Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 28 Sep 2022 10:20:08 +0200 Subject: [PATCH] Add colors.h --- src/cnn/initialisation.c | 10 ++++++---- src/cnn/main.c | 4 +++- src/cnn/make.c | 8 +++++--- src/cnn/neuron_io.c | 2 +- src/colors.h | 34 ++++++++++++++++++++++++++++++++++ test/cnn_neuron_io.c | 9 +++++++-- 6 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 src/colors.h diff --git a/src/cnn/initialisation.c b/src/cnn/initialisation.c index fa4ad09..8bb02ca 100644 --- a/src/cnn/initialisation.c +++ b/src/cnn/initialisation.c @@ -1,10 +1,12 @@ #include #include + +#include "../colors.h" #include "include/initialisation.h" void initialisation_1d_matrix(int initialisation, float* matrix, int rows, int n) { // TODO - printf("\033[33;1m[WARNING]\033[0m Appel de initialisation_1d_matrix, incomplet\n"); + printf_warning("Appel de initialisation_1d_matrix, incomplet\n"); float lower_bound = -6/sqrt((double)n); float distance = -lower_bound-lower_bound; for (int i=0; i < rows; i++) { @@ -13,7 +15,7 @@ void initialisation_1d_matrix(int initialisation, float* matrix, int rows, int n } void initialisation_2d_matrix(int initialisation, float** matrix, int rows, int columns, int n) { // TODO - printf("\033[33;1m[WARNING]\033[0m Appel de initialisation_2d_matrix, incomplet\n"); + printf_warning("Appel de initialisation_2d_matrix, incomplet\n"); float lower_bound = -6/sqrt((double)n); float distance = -lower_bound-lower_bound; for (int i=0; i < rows; i++) { @@ -24,7 +26,7 @@ void initialisation_2d_matrix(int initialisation, float** matrix, int rows, int } void initialisation_3d_matrix(int initialisation, float*** matrix, int depth, int rows, int columns, int n) { // TODO - printf("\033[33;1m[WARNING]\033[0m Appel de initialisation_3d_matrix, incomplet\n"); + printf_warning("Appel de initialisation_3d_matrix, incomplet\n"); float lower_bound = -6/sqrt((double)n); float distance = -lower_bound-lower_bound; for (int i=0; i < depth; i++) { @@ -37,7 +39,7 @@ void initialisation_3d_matrix(int initialisation, float*** matrix, int depth, in } void initialisation_4d_matrix(int initialisation, float**** matrix, int rows, int columns, int rows1, int columns1, int n) { // TODO - printf("\033[33;1m[WARNING]\033[0m Appel de initialisation_4d_matrix, incomplet\n"); + printf_warning("Appel de initialisation_4d_matrix, incomplet\n"); float lower_bound = -6/sqrt((double)n); float distance = -lower_bound-lower_bound; for (int i=0; i < rows; i++) { diff --git a/src/cnn/main.c b/src/cnn/main.c index a93500a..7bc12d7 100644 --- a/src/cnn/main.c +++ b/src/cnn/main.c @@ -2,6 +2,8 @@ #include #include #include + +#include "../colors.h" #include "include/initialisation.h" #include "function.c" #include "creation.c" @@ -79,7 +81,7 @@ void forward_propagation(Network* network) { } void backward_propagation(Network* network, float wanted_number) { // TODO - printf("\033[33;1m[WARNING]\033[0m Appel de backward_propagation, incomplet\n"); + printf_warning("Appel de backward_propagation, incomplet\n"); float* wanted_output = generate_wanted_output(wanted_number); int n = network->size-1; float loss = compute_cross_entropy_loss(network->input[n][0][0], wanted_output, network->width[n]); diff --git a/src/cnn/make.c b/src/cnn/make.c index 94803e8..8e2a83d 100644 --- a/src/cnn/make.c +++ b/src/cnn/make.c @@ -1,9 +1,11 @@ #include + +#include "../colors.h" #include "include/make.h" void make_convolution(float*** input, Kernel_cnn* kernel, float*** output, int output_dim) { // TODO, MISS CONDITIONS ON THE CONVOLUTION - printf("\033[33;1m[WARNING]\033[0m Appel de make_convolution, incomplet\n"); + printf_warning("Appel de make_convolution, incomplet\n"); float f; int n = kernel->k_size; printf("Convolution output: %dx%dx%d, %dx%dx%d\n", kernel->columns, output_dim, output_dim, kernel->rows, n, n); @@ -27,7 +29,7 @@ void make_convolution(float*** input, Kernel_cnn* kernel, float*** output, int o void make_average_pooling(float*** input, float*** output, int size, int output_depth, int output_dim) { // TODO, MISS CONDITIONS ON THE POOLING - printf("\033[33;1m[WARNING]\033[0m Appel de make_average_pooling, incomplet\n"); + printf_warning("Appel de make_average_pooling, incomplet\n"); float average; int n = size*size; for (int i=0; i < output_depth; i++) { @@ -47,7 +49,7 @@ void make_average_pooling(float*** input, float*** output, int size, int output_ void make_average_pooling_flattened(float*** input, float* output, int size, int input_depth, int input_dim) { if ((input_depth*input_dim*input_dim) % (size*size) != 0) { - printf("Erreur, deux layers non compatibles avec un average pooling flattened"); + printf_error("Deux layers non compatibles avec un average pooling flattened"); return; } float average; diff --git a/src/cnn/neuron_io.c b/src/cnn/neuron_io.c index 33a5841..9b901e5 100644 --- a/src/cnn/neuron_io.c +++ b/src/cnn/neuron_io.c @@ -119,7 +119,7 @@ Network* read_network(char* filename) { FILE *ptr; Network* network = (Network*)malloc(sizeof(Network)); // TODO: malloc pour network -> input - printf("\033[33;1m[WARNING]\033[0m Chargement depuis un fichier, network->input ne sera pas alloué\n"); + printf_warning("Chargement depuis un fichier, network->input ne sera pas alloué\n"); ptr = fopen(filename, "rb"); diff --git a/src/colors.h b/src/colors.h new file mode 100644 index 0000000..459220a --- /dev/null +++ b/src/colors.h @@ -0,0 +1,34 @@ +#ifndef DEF_COLORS_H +#define DEF_COLORS_H + +#define RESET "\033[0m" +#define BLACK "\033[30m" /* Black */ +#define RED "\033[31m" /* Red */ +#define GREEN "\033[32m" /* Green */ +#define YELLOW "\033[33m" /* Yellow */ +#define BLUE "\033[34m" /* Blue */ +#define MAGENTA "\033[35m" /* Magenta */ +#define CYAN "\033[36m" /* Cyan */ +#define WHITE "\033[37m" /* White */ +#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ +#define BOLDRED "\033[1m\033[31m" /* Bold Red */ +#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ +#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ +#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ +#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ +#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ +#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ + +void printf_error(char* string) { + printf(BOLDRED "[ ERROR ]" RESET " %s", string); +} + +void printf_warning(char* string) { + printf(BOLDYELLOW "[WARNING]" RESET " %s", string); +} + +void printf_info(char* string) { + printf(BOLDBLUE "[ INFO ]" RESET " %s", string); +} + +#endif \ No newline at end of file diff --git a/test/cnn_neuron_io.c b/test/cnn_neuron_io.c index 8594568..6a4e914 100644 --- a/test/cnn_neuron_io.c +++ b/test/cnn_neuron_io.c @@ -3,6 +3,7 @@ #include #include +#include "../src/colors.h" #include "../src/cnn/neuron_io.c" #include "../src/cnn/creation.c" @@ -22,9 +23,13 @@ int main() { printf("OK\n"); /* - printf("Réécriture du nouveau réseau\n"); - write_network(".test-cache/cnn_neuron_io_2.bin", network2); + printf("Vérification de l'égalité des réseaux\n"); + if (! equals_networks(network, network2)) { + printf_error("Les deux réseaux obtenus ne sont pas égaux.\n"); + exit(1); + } printf("OK\n"); */ + return 0; } \ No newline at end of file