Use printf_error and printf_warning when needed

This commit is contained in:
augustin64 2023-02-28 13:14:51 +01:00
parent 4b87b19188
commit 79312caace
5 changed files with 48 additions and 35 deletions

View File

@ -3,6 +3,7 @@
#include "../include/memory_management.h" #include "../include/memory_management.h"
#include "include/initialisation.h" #include "include/initialisation.h"
#include "../include/colors.h"
#include "include/function.h" #include "include/function.h"
#include "../include/utils.h" #include "../include/utils.h"
@ -10,7 +11,7 @@
Network* create_network(int max_size, float learning_rate, int dropout, int initialisation, int input_dim, int input_depth) { Network* create_network(int max_size, float learning_rate, int dropout, int initialisation, int input_dim, int input_depth) {
if (dropout < 0 || dropout > 100) { if (dropout < 0 || dropout > 100) {
printf("Erreur, la probabilité de dropout n'est pas respecté, elle doit être comprise entre 0 et 100\n"); printf_error("la probabilité de dropout n'est pas respecté, elle doit être comprise entre 0 et 100\n");
} }
Network* network = (Network*)nalloc(1, sizeof(Network)); Network* network = (Network*)nalloc(1, sizeof(Network));
network->learning_rate = learning_rate; network->learning_rate = learning_rate;
@ -102,11 +103,11 @@ void add_2d_average_pooling(Network* network, int dim_output) {
int k_pos = n-1; int k_pos = n-1;
int dim_input = network->width[k_pos]; int dim_input = network->width[k_pos];
if (network->max_size == n) { if (network->max_size == n) {
printf("Impossible de rajouter une couche d'average pooling, le réseau est déjà plein\n"); printf_error("Impossible de rajouter une couche d'average pooling, le réseau est déjà plein\n");
return; return;
} }
if (dim_input%dim_output != 0) { if (dim_input%dim_output != 0) {
printf("Erreur de dimension dans l'average pooling\n"); printf_error("Dimension de l'average pooling incorrecte\n");
return; return;
} }
network->kernel[k_pos]->cnn = NULL; network->kernel[k_pos]->cnn = NULL;
@ -124,11 +125,11 @@ void add_2d_max_pooling(Network* network, int dim_output) {
int k_pos = n-1; int k_pos = n-1;
int dim_input = network->width[k_pos]; int dim_input = network->width[k_pos];
if (network->max_size == n) { if (network->max_size == n) {
printf("Impossible de rajouter une couche de max pooling, le réseau est déjà plein\n"); printf_error("Impossible de rajouter une couche de max pooling, le réseau est déjà plein\n");
return; return;
} }
if (dim_input%dim_output != 0) { if (dim_input%dim_output != 0) {
printf("Erreur de dimension dans le max pooling\n"); printf_error("Dimension du max pooling incorrecte\n");
return; return;
} }
network->kernel[k_pos]->cnn = NULL; network->kernel[k_pos]->cnn = NULL;
@ -145,7 +146,7 @@ void add_convolution(Network* network, int depth_output, int dim_output, int act
int n = network->size; int n = network->size;
int k_pos = n-1; int k_pos = n-1;
if (network->max_size == n) { if (network->max_size == n) {
printf("Impossible de rajouter une couche de convolution, le réseau est déjà plein \n"); printf_error("Impossible de rajouter une couche de convolution, le réseau est déjà plein \n");
return; return;
} }
int depth_input = network->depth[k_pos]; int depth_input = network->depth[k_pos];
@ -207,7 +208,7 @@ void add_dense(Network* network, int size_output, int activation) {
int k_pos = n-1; int k_pos = n-1;
int size_input = network->width[k_pos]; int size_input = network->width[k_pos];
if (network->max_size == n) { if (network->max_size == n) {
printf("Impossible de rajouter une couche dense, le réseau est déjà plein\n"); printf_error("Impossible de rajouter une couche dense, le réseau est déjà plein\n");
return; return;
} }
network->kernel[k_pos]->cnn = NULL; network->kernel[k_pos]->cnn = NULL;
@ -248,7 +249,7 @@ void add_dense_linearisation(Network* network, int size_output, int activation)
int k_pos = n-1; int k_pos = n-1;
int size_input = network->depth[k_pos]*network->width[k_pos]*network->width[k_pos]; int size_input = network->depth[k_pos]*network->width[k_pos]*network->width[k_pos];
if (network->max_size == n) { if (network->max_size == n) {
printf("Impossible de rajouter une couche dense, le réseau est déjà plein\n"); printf_error("Impossible de rajouter une couche dense, le réseau est déjà plein\n");
return; return;
} }
network->kernel[k_pos]->cnn = NULL; network->kernel[k_pos]->cnn = NULL;

View File

@ -4,6 +4,7 @@
#include "include/free.h" #include "include/free.h"
#include "include/struct.h" #include "include/struct.h"
#include "../include/colors.h"
#include "include/neuron_io.h" #include "include/neuron_io.h"
@ -67,7 +68,7 @@ void print_poids_ker_cnn(char* modele) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if (argc < 2) { if (argc < 2) {
printf("Pas d'action spécifiée\n"); printf_error("Pas d'action spécifiée\n");
help(argv[0]); help(argv[0]);
return 1; return 1;
} }
@ -79,18 +80,20 @@ int main(int argc, char* argv[]) {
modele = argv[i+1]; modele = argv[i+1];
i += 2; i += 2;
} else { } else {
printf("Option choisie inconnue: %s\n", argv[i]); printf_warning("Option choisie inconnue: ");
printf("%s\n", argv[i]);
i++; i++;
} }
} }
if (!modele) { if (!modele) {
printf("Pas de modèle à utiliser spécifié.\n"); printf_error("Pas de modèle à utiliser spécifié.\n");
return 1; return 1;
} }
print_poids_ker_cnn(modele); print_poids_ker_cnn(modele);
return 0; return 0;
} }
printf("Option choisie non reconnue: %s\n", argv[1]); printf_error("Option choisie non reconnue: ");
printf("%s\n", argv[1]);
help(argv[0]); help(argv[0]);
return 1; return 1;
} }

View File

@ -2,6 +2,8 @@
#include <math.h> #include <math.h>
#include <float.h> #include <float.h>
#include "../include/colors.h"
#include "include/function.h" #include "include/function.h"
@ -107,7 +109,8 @@ void choose_apply_function_matrix(int activation, float*** input, int depth, int
} else if (activation == LEAKY_RELU) { } else if (activation == LEAKY_RELU) {
apply_function_input(leaky_relu, input, depth, dim, dim); apply_function_input(leaky_relu, input, depth, dim, dim);
} else { } else {
printf("Erreur, fonction d'activation inconnue (choose_apply_function_matrix): %d\n", activation); printf_error("fonction d'activation inconnue (apply_function_to_matrix): ");
printf("%d\n", activation);
} }
} }
@ -123,7 +126,8 @@ void choose_apply_function_vector(int activation, float*** input, int dim) {
} else if (activation == LEAKY_RELU) { } else if (activation == LEAKY_RELU) {
apply_function_input(leaky_relu, input, 1, 1, dim); apply_function_input(leaky_relu, input, 1, 1, dim);
} else { } else {
printf("Erreur, fonction d'activation inconnue (choose_apply_function_vector): %d\n", activation); printf_error("fonction d'activation inconnue (apply_function_to_vector): ");
printf("%d\n", activation);
} }
} }
@ -147,11 +151,11 @@ ptr get_function_activation(int activation) {
return &sigmoid_derivative; return &sigmoid_derivative;
} }
if (activation == SOFTMAX) { if (activation == SOFTMAX) {
printf("Erreur, impossible de renvoyer la fonction softmax\n"); printf_error("impossible de renvoyer la fonction softmax\n");
return NULL; return NULL;
} }
if (activation == -SOFTMAX) { if (activation == -SOFTMAX) {
printf("Erreur, impossible de renvoyer la dérivée de la fonction softmax\n"); printf_error("impossible de renvoyer la dérivée de la fonction softmax\n");
return NULL; return NULL;
} }
if (activation == TANH) { if (activation == TANH) {
@ -166,6 +170,7 @@ ptr get_function_activation(int activation) {
if (activation == -LEAKY_RELU) { if (activation == -LEAKY_RELU) {
return &leaky_relu_derivative; return &leaky_relu_derivative;
} }
printf("Erreur, fonction d'activation inconnue (choose_apply_function_vector): %d\n", activation); printf_error("fonction d'activation inconnue (get_activation_function): ");
printf("%d\n", activation);
return NULL; return NULL;
} }

View File

@ -45,7 +45,7 @@ void help(char* call) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if (argc < 2) { if (argc < 2) {
printf("Pas d'action spécifiée\n"); printf_error("Pas d'action spécifiée\n");
help(argv[0]); help(argv[0]);
return 1; return 1;
} }
@ -87,30 +87,31 @@ int main(int argc, char* argv[]) {
recover = argv[i+1]; recover = argv[i+1];
i += 2; i += 2;
} else { } else {
printf("Option choisie inconnue: %s\n", argv[i]); printf_warning("Option choisie inconnue: ");
printf("%s\n", argv[i]);
i++; i++;
} }
} }
if ((dataset!=NULL) && !strcmp(dataset, "mnist")) { if ((dataset!=NULL) && !strcmp(dataset, "mnist")) {
dataset_type = 0; dataset_type = 0;
if (!images_file) { if (!images_file) {
printf("Pas de fichier d'images spécifié\n"); printf_error("Pas de fichier d'images spécifié\n");
return 1; return 1;
} }
if (!labels_file) { if (!labels_file) {
printf("Pas de fichier de labels spécifié\n"); printf_error("Pas de fichier de labels spécifié\n");
return 1; return 1;
} }
} }
else if ((dataset!=NULL) && !strcmp(dataset, "jpg")) { else if ((dataset!=NULL) && !strcmp(dataset, "jpg")) {
dataset_type = 1; dataset_type = 1;
if (!data_dir) { if (!data_dir) {
printf("Pas de dossier de données spécifié.\n"); printf_error("Pas de dossier de données spécifié.\n");
return 1; return 1;
} }
} }
else { else {
printf("Pas de type de dataset spécifié.\n"); printf_error("Pas de type de dataset spécifié.\n");
return 1; return 1;
} }
if (!out) { if (!out) {
@ -155,35 +156,36 @@ int main(int argc, char* argv[]) {
i++; i++;
} }
else { else {
printf("Option choisie inconnue: %s\n", argv[i]); printf_warning("Option choisie inconnue: ");
printf("%s\n", argv[i]);
i++; i++;
} }
} }
if ((dataset!=NULL) && !strcmp(dataset, "mnist")) { if ((dataset!=NULL) && !strcmp(dataset, "mnist")) {
dataset_type = 0; dataset_type = 0;
if (!images_file) { if (!images_file) {
printf("Pas de fichier d'images spécifié\n"); printf_error("Pas de fichier d'images spécifié\n");
return 1; return 1;
} }
if (!labels_file) { if (!labels_file) {
printf("Pas de fichier de labels spécifié\n"); printf_error("Pas de fichier de labels spécifié\n");
return 1; return 1;
} }
} }
else if ((dataset!=NULL) && !strcmp(dataset, "jpg")) { else if ((dataset!=NULL) && !strcmp(dataset, "jpg")) {
dataset_type = 1; dataset_type = 1;
if (!data_dir) { if (!data_dir) {
printf("Pas de dossier de données spécifié.\n"); printf_error("Pas de dossier de données spécifié.\n");
return 1; return 1;
} }
} }
else { else {
printf("Pas de type de dataset spécifié.\n"); printf_error("Pas de type de dataset spécifié.\n");
return 1; return 1;
} }
if (!modele) { if (!modele) {
printf("Pas de modèle à utiliser spécifié.\n"); printf_error("Pas de modèle à utiliser spécifié.\n");
return 1; return 1;
} }
test_network(dataset_type, modele, images_file, labels_file, data_dir, preview_fails); test_network(dataset_type, modele, images_file, labels_file, data_dir, preview_fails);
@ -213,7 +215,8 @@ int main(int argc, char* argv[]) {
input_file = argv[i+1]; input_file = argv[i+1];
i += 2; i += 2;
} else { } else {
printf("Option choisie inconnue: %s\n", argv[i]); printf_warning("Option choisie inconnue: ");
printf("%s\n", argv[i]);
i++; i++;
} }
} }
@ -223,24 +226,25 @@ int main(int argc, char* argv[]) {
dataset_type = 1; dataset_type = 1;
} }
else { else {
printf("Pas de type de dataset spécifié.\n"); printf_error("Pas de type de dataset spécifié.\n");
return 1; return 1;
} }
if (!input_file) { if (!input_file) {
printf("Pas de fichier d'entrée spécifié, rien à faire.\n"); printf_error("Pas de fichier d'entrée spécifié, rien à faire.\n");
return 1; return 1;
} }
if (!out) { if (!out) {
out = "text"; out = "text";
} }
if (!modele) { if (!modele) {
printf("Pas de modèle à utiliser spécifié.\n"); printf_error("Pas de modèle à utiliser spécifié.\n");
return 1; return 1;
} }
recognize(dataset_type, modele, input_file, out); recognize(dataset_type, modele, input_file, out);
return 0; return 0;
} }
printf("Option choisie non reconnue: %s\n", argv[1]); printf_error("Option choisie non reconnue: ");
printf("%s\n", argv[1]);
help(argv[0]); help(argv[0]);
return 1; return 1;
} }

View File

@ -153,7 +153,7 @@ Network* read_network(char* filename) {
fread(&magic, sizeof(uint32_t), 1, ptr); fread(&magic, sizeof(uint32_t), 1, ptr);
if (magic != MAGIC_NUMBER) { if (magic != MAGIC_NUMBER) {
printf("Incorrect magic number !\n"); printf_error("Incorrect magic number !\n");
exit(1); exit(1);
} }