From a604c96476da715ab82e95582426227c976098f9 Mon Sep 17 00:00:00 2001 From: Julien Chemillier Date: Mon, 3 Oct 2022 10:04:11 +0200 Subject: [PATCH] Add learning rate --- src/cnn/creation.c | 7 ++++--- src/cnn/include/creation.h | 4 ++-- src/cnn/include/struct.h | 1 + src/cnn/main.c | 2 +- src/cnn/train.c | 2 +- test/cnn_neuron_io.c | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cnn/creation.c b/src/cnn/creation.c index a46a126..732a34c 100644 --- a/src/cnn/creation.c +++ b/src/cnn/creation.c @@ -4,11 +4,12 @@ #include "include/function.h" #include "initialisation.c" -Network* create_network(int max_size, int dropout, int initialisation, int input_dim, int input_depth) { +Network* create_network(int max_size, int learning_rate, int dropout, int initialisation, int input_dim, int input_depth) { if (dropout < 0 || dropout > 100) { printf("Erreur, la probabilité de dropout n'est pas respecté, elle doit être comprise entre 0 et 100\n"); } Network* network = (Network*)malloc(sizeof(Network)); + network->learning_rate = learning_rate; network->max_size = max_size; network->dropout = dropout; network->initialisation = initialisation; @@ -28,8 +29,8 @@ Network* create_network(int max_size, int dropout, int initialisation, int input return network; } -Network* create_network_lenet5(int dropout, int activation, int initialisation, int input_dim, int input_depth) { - Network* network = create_network(8, dropout, initialisation, input_dim, input_depth); +Network* create_network_lenet5(int learning_rate, int dropout, int activation, int initialisation, int input_dim, int input_depth) { + Network* network = create_network(8, learning_rate, dropout, initialisation, input_dim, input_depth); network->kernel[0]->activation = activation; network->kernel[0]->linearisation = 0; add_convolution(network, 1, 32, 6, 28, activation); diff --git a/src/cnn/include/creation.h b/src/cnn/include/creation.h index 23cd247..126b8c3 100644 --- a/src/cnn/include/creation.h +++ b/src/cnn/include/creation.h @@ -7,12 +7,12 @@ /* * Créé un réseau qui peut contenir max_size couche (dont celle d'input et d'output) */ -Network* create_network(int max_size, int dropout, int initialisation, int input_dim, int input_depth); +Network* create_network(int max_size, int learning_rate, int dropout, int initialisation, int input_dim, int input_depth); /* * Renvoie un réseau suivant l'architecture LeNet5 */ -Network* create_network_lenet5(int dropout, int activation, int initialisation, int input_dim, int input_depth); +Network* create_network_lenet5(int learning_rate, int dropout, int activation, int initialisation, int input_dim, int input_depth); /* * Créé et alloue de la mémoire à une couche de type input cube diff --git a/src/cnn/include/struct.h b/src/cnn/include/struct.h index 706a8ab..3183f5a 100644 --- a/src/cnn/include/struct.h +++ b/src/cnn/include/struct.h @@ -30,6 +30,7 @@ typedef struct Kernel { typedef struct Network{ int dropout; // Contient la probabilité d'abandon d'un neurone dans [0, 100] (entiers) + int learning_rate; int initialisation; // Contient le type d'initialisation int max_size; // Taille du tableau contenant le réseau int size; // Taille actuelle du réseau (size ≤ max_size) diff --git a/src/cnn/main.c b/src/cnn/main.c index 6fb1a29..2629fd3 100644 --- a/src/cnn/main.c +++ b/src/cnn/main.c @@ -27,7 +27,7 @@ void help(char* call) { void dev_conv() { - Network* network = create_network_lenet5(0, TANH, GLOROT_NORMAL, 32, 1); + Network* network = create_network_lenet5(0, 0, TANH, GLOROT_NORMAL, 32, 1); forward_propagation(network); } diff --git a/src/cnn/train.c b/src/cnn/train.c index daa83ae..cef9af8 100644 --- a/src/cnn/train.c +++ b/src/cnn/train.c @@ -77,7 +77,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di } // Initialisation du réseau - Network* network = create_network_lenet5(0, TANH, GLOROT_NORMAL, input_dim, input_depth); + Network* network = create_network_lenet5(0, 0, TANH, GLOROT_NORMAL, input_dim, input_depth); #ifdef USE_MULTITHREADING // Récupération du nombre de threads disponibles diff --git a/test/cnn_neuron_io.c b/test/cnn_neuron_io.c index 476b834..9821295 100644 --- a/test/cnn_neuron_io.c +++ b/test/cnn_neuron_io.c @@ -12,7 +12,7 @@ int main() { printf("Création du réseau\n"); - Network* network = create_network_lenet5(0, 3, 2, 32, 1); + Network* network = create_network_lenet5(0, 0, 3, 2, 32, 1); printf("OK\n"); printf("Écriture du réseau\n");