From 19030a4f01db60a63d271c297c52aa66f69fc6e6 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 4 Nov 2022 12:53:38 +0100 Subject: [PATCH 1/4] Update workflow file --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9e9275e..c35de67 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,8 +13,8 @@ jobs: steps: - uses: actions/checkout@v3 - - name: print versions - run: make --version; gcc --version + - name: make all + run: make all - name: run-tests run: make run-tests - name: mnist main train From 70e0ed08b7b220390a76433ad010e3bf7d091540 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Tue, 8 Nov 2022 19:56:58 +0100 Subject: [PATCH 2/4] Update mnist utils --- src/mnist/utils.c | 2 +- test/mnist_utils.sh | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mnist/utils.c b/src/mnist/utils.c index 8e61851..a5cf8e9 100644 --- a/src/mnist/utils.c +++ b/src/mnist/utils.c @@ -78,7 +78,7 @@ void count_labels(char* filename) { } for (int i=0; i < 10; i++) { - printf("Nombre de %d: %x\n", i, tab[i]); + printf("Nombre de %d: %u\n", i, tab[i]); } free(labels); } diff --git a/test/mnist_utils.sh b/test/mnist_utils.sh index fed2f21..5a801b2 100755 --- a/test/mnist_utils.sh +++ b/test/mnist_utils.sh @@ -3,14 +3,15 @@ set -e OUT="build" -[[ -f "$OUT/mnist-utils" ]] || make $OUT/mnist-utils +make $OUT/mnist-utils echo "Compte des labels" -"$OUT/mnist-utils" count-labels -l data/mnist/t10k-labels-idx1-ubyte > /dev/null +"$OUT/mnist-utils" count-labels -l data/mnist/t10k-labels-idx1-ubyte echo "OK" echo "Création du réseau" -"$OUT/mnist-utils" creer-reseau -n 3 -o .test-cache/reseau.bin > /dev/null +mkdir -p .test-cache +"$OUT/mnist-utils" creer-reseau -n 3 -o .test-cache/reseau.bin echo "OK" echo "Affichage poids" From 5a34311dfbb7d7a9d0307238fb99efb7f38cd219 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Tue, 8 Nov 2022 19:57:13 +0100 Subject: [PATCH 3/4] Update cnn utils --- src/cnn/utils.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/cnn/utils.c b/src/cnn/utils.c index d794f6a..d02f73b 100644 --- a/src/cnn/utils.c +++ b/src/cnn/utils.c @@ -12,12 +12,13 @@ if (network1->var != network2->var) { \ printf_error("network1->" name " et network2->" name " ne sont pas égaux\n"); \ if (indice != -1) { \ - printf(BOLDBLUE"[ INFO_ ]"RESET" indice: %d\n", indice); \ + printf(BOLDBLUE"[ INFO_ ]" RESET " indice: %d\n", indice); \ } \ return false; \ } bool equals_networks(Network* network1, Network* network2) { + int output_dim; checkEquals(size, "size", -1); checkEquals(initialisation, "initialisation", -1); checkEquals(dropout, "dropout", -1); @@ -50,12 +51,13 @@ bool equals_networks(Network* network1, Network* network2) { } } else { // Type CNN + output_dim = network1->width[i]; checkEquals(kernel[i]->cnn->k_size, "kernel[i]->k_size", i); checkEquals(kernel[i]->cnn->rows, "kernel[i]->rows", i); checkEquals(kernel[i]->cnn->columns, "kernel[i]->columns", i); for (int j=0; j < network1->kernel[i]->cnn->columns; j++) { - for (int k=0; k < network1->kernel[i]->cnn->k_size; k++) { - for (int l=0; l < network1->kernel[i]->cnn->k_size; l++) { + for (int k=0; k < output_dim; k++) { + for (int l=0; l < output_dim; l++) { checkEquals(kernel[i]->cnn->bias[j][k][l], "kernel[i]->cnn->bias[j][k][l]", l); } } @@ -87,6 +89,7 @@ Network* copy_network(Network* network) { int rows; int k_size; int columns; + int output_dim; copyVar(dropout); copyVar(learning_rate); @@ -149,6 +152,8 @@ Network* copy_network(Network* network) { rows = network->kernel[i]->cnn->rows; k_size = network->kernel[i]->cnn->k_size; columns = network->kernel[i]->cnn->columns; + output_dim = network->width[i]; + network_cp->kernel[i]->nn = NULL; network_cp->kernel[i]->cnn = (Kernel_cnn*)malloc(sizeof(Kernel_cnn)); @@ -160,12 +165,12 @@ Network* copy_network(Network* network) { network_cp->kernel[i]->cnn->bias = (float***)malloc(sizeof(float**)*columns); network_cp->kernel[i]->cnn->d_bias = (float***)malloc(sizeof(float**)*columns); for (int j=0; j < columns; j++) { - network_cp->kernel[i]->cnn->bias[j] = (float**)malloc(sizeof(float*)*k_size); - network_cp->kernel[i]->cnn->d_bias[j] = (float**)malloc(sizeof(float*)*k_size); - for (int k=0; k < k_size; k++) { - network_cp->kernel[i]->cnn->bias[j][k] = (float*)malloc(sizeof(float)*k_size); - network_cp->kernel[i]->cnn->d_bias[j][k] = (float*)malloc(sizeof(float)*k_size); - for (int l=0; l < k_size; l++) { + network_cp->kernel[i]->cnn->bias[j] = (float**)malloc(sizeof(float*)*output_dim); + network_cp->kernel[i]->cnn->d_bias[j] = (float**)malloc(sizeof(float*)*output_dim); + for (int k=0; k < output_dim; k++) { + network_cp->kernel[i]->cnn->bias[j][k] = (float*)malloc(sizeof(float)*output_dim); + network_cp->kernel[i]->cnn->d_bias[j][k] = (float*)malloc(sizeof(float)*output_dim); + for (int l=0; l < output_dim; l++) { copyVar(kernel[i]->cnn->bias[j][k][l]); network_cp->kernel[i]->cnn->d_bias[j][k][l] = 0.; } From 60473ed56751c75eaf559b7d67f3b88471ab2a5f Mon Sep 17 00:00:00 2001 From: augustin64 Date: Tue, 8 Nov 2022 19:57:27 +0100 Subject: [PATCH 4/4] Update cnn neuron_io --- src/cnn/include/neuron_io.h | 4 ++-- src/cnn/neuron_io.c | 29 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/cnn/include/neuron_io.h b/src/cnn/include/neuron_io.h index 98e7790..5445b76 100644 --- a/src/cnn/include/neuron_io.h +++ b/src/cnn/include/neuron_io.h @@ -20,7 +20,7 @@ void write_network(char* filename, Network* network); /* * Écrit une couche dans le fichier spécifié par le pointeur ptr */ -void write_couche(Kernel* kernel, int type_couche, FILE* ptr); +void write_couche(Network* network, int indice_couche, int type_couche, FILE* ptr); // Lecture d'un réseau neuronal @@ -33,5 +33,5 @@ Network* read_network(char* filename); /* * Lit une kernel dans le fichier spécifié par le pointeur ptr */ -Kernel* read_kernel(int type_couche, FILE* ptr); +Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr); #endif \ No newline at end of file diff --git a/src/cnn/neuron_io.c b/src/cnn/neuron_io.c index c3935f9..e838913 100644 --- a/src/cnn/neuron_io.c +++ b/src/cnn/neuron_io.c @@ -47,17 +47,19 @@ void write_network(char* filename, Network* network) { // Écriture du pré-corps et corps for (int i=0; i < size; i++) { - write_couche(network->kernel[i], type_couche[i], ptr); + write_couche(network, i, type_couche[i], ptr); } fclose(ptr); } -void write_couche(Kernel* kernel, int type_couche, FILE* ptr) { +void write_couche(Network* network, int indice_couche, int type_couche, FILE* ptr) { + Kernel* kernel = network->kernel[indice_couche]; int indice_buffer = 0; if (type_couche == 0) { // Cas du CNN Kernel_cnn* cnn = kernel->cnn; + int output_dim = network->width[indice_couche]; // Écriture du pré-corps uint32_t pre_buffer[4]; @@ -68,11 +70,12 @@ void write_couche(Kernel* kernel, int type_couche, FILE* ptr) { fwrite(pre_buffer, sizeof(pre_buffer), 1, ptr); // Écriture du corps - float buffer[cnn->k_size*cnn->k_size*cnn->columns*(cnn->rows+1)]; + float buffer[cnn->columns*(cnn->k_size*cnn->k_size*cnn->rows+output_dim*output_dim)]; for (int i=0; i < cnn->columns; i++) { - for (int j=0; j < cnn->k_size; j++) { - for (int k=0; k < cnn->k_size; k++) { + for (int j=0; j < output_dim; j++) { + for (int k=0; k < output_dim; k++) { + printf("%f\n", cnn->bias[i][j][k]); bufferAdd(cnn->bias[i][j][k]); } } @@ -166,7 +169,7 @@ Network* read_network(char* filename) { network->kernel = (Kernel**)malloc(sizeof(Kernel*)*size); for (int i=0; i < (int)size; i++) { - network->kernel[i] = read_kernel(type_couche[i], ptr); + network->kernel[i] = read_kernel(type_couche[i], network->width[i], ptr); } network->input = (float****)malloc(sizeof(float***)*size); @@ -187,7 +190,7 @@ Network* read_network(char* filename) { return network; } -Kernel* read_kernel(int type_couche, FILE* ptr) { +Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr) { Kernel* kernel = (Kernel*)malloc(sizeof(Kernel)); if (type_couche == 0) { // Cas du CNN // Lecture du "Pré-corps" @@ -209,12 +212,12 @@ Kernel* read_kernel(int type_couche, FILE* ptr) { cnn->bias = (float***)malloc(sizeof(float**)*cnn->columns); cnn->d_bias = (float***)malloc(sizeof(float**)*cnn->columns); for (int i=0; i < cnn->columns; i++) { - cnn->bias[i] = (float**)malloc(sizeof(float*)*cnn->k_size); - cnn->d_bias[i] = (float**)malloc(sizeof(float*)*cnn->k_size); - for (int j=0; j < cnn->k_size; j++) { - cnn->bias[i][j] = (float*)malloc(sizeof(float)*cnn->k_size); - cnn->d_bias[i][j] = (float*)malloc(sizeof(float)*cnn->k_size); - for (int k=0; k < cnn->k_size; k++) { + cnn->bias[i] = (float**)malloc(sizeof(float*)*output_dim); + cnn->d_bias[i] = (float**)malloc(sizeof(float*)*output_dim); + for (int j=0; j < output_dim; j++) { + cnn->bias[i][j] = (float*)malloc(sizeof(float)*output_dim); + cnn->d_bias[i][j] = (float*)malloc(sizeof(float)*output_dim); + for (int k=0; k < output_dim; k++) { fread(&tmp, sizeof(tmp), 1, ptr); cnn->bias[i][j][k] = tmp; cnn->d_bias[i][j][k] = 0.;