From 6917711271f8d81951dbcb53f7facfeaf9774f1d Mon Sep 17 00:00:00 2001 From: augustin64 Date: Tue, 17 Jan 2023 12:50:13 +0100 Subject: [PATCH] Update the way of reading the network --- src/cnn/neuron_io.c | 7 +++---- src/cnn/utils.c | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cnn/neuron_io.c b/src/cnn/neuron_io.c index 32fe7f8..11fd105 100644 --- a/src/cnn/neuron_io.c +++ b/src/cnn/neuron_io.c @@ -32,7 +32,7 @@ void write_network(char* filename, Network* network) { bufferAdd(network->depth[i]); } - for (int i=0; i < size; i++) { + for (int i=0; i < size-1; i++) { if ((!network->kernel[i]->cnn)&&(!network->kernel[i]->nn)) { type_couche[i] = 2; } else if (!network->kernel[i]->cnn) { @@ -46,7 +46,7 @@ void write_network(char* filename, Network* network) { fwrite(buffer, sizeof(buffer), 1, ptr); // Écriture du pré-corps et corps - for (int i=0; i < size; i++) { + for (int i=0; i < size-1; i++) { write_couche(network, i, type_couche[i], ptr); } @@ -168,12 +168,11 @@ Network* read_network(char* filename) { } // Lecture de chaque couche - network->kernel = (Kernel**)malloc(sizeof(Kernel*)*size); + network->kernel = (Kernel**)malloc(sizeof(Kernel*)*(size-1)); for (int i=0; i < (int)size-1; i++) { network->kernel[i] = read_kernel(type_couche[i], network->width[i+1], ptr); } - network->kernel[(int)size-1] = read_kernel(type_couche[(int)size-1], -1, ptr); network->input = (float****)malloc(sizeof(float***)*size); for (int i=0; i < (int)size; i++) { // input[size][couche->depth][couche->dim][couche->dim] diff --git a/src/cnn/utils.c b/src/cnn/utils.c index d9397f9..601ec92 100644 --- a/src/cnn/utils.c +++ b/src/cnn/utils.c @@ -40,7 +40,7 @@ bool equals_networks(Network* network1, Network* network2) { checkEquals(depth[i], "input_depth", i); } - for (int i=0; i < network1->size; i++) { + for (int i=0; i < network1->size-1; i++) { checkEquals(kernel[i]->activation, "kernel[i]->activation", i); if ((!network1->kernel[i]->cnn ^ !network2->kernel[i]->cnn) || (!network1->kernel[i]->nn ^ !network2->kernel[i]->nn)) { printf(BOLDRED "[ ERROR ]" RESET "network1->kernel[%d] et network1->kernel[%d] diffèrent de type\n", i, i); @@ -118,8 +118,8 @@ Network* copy_network(Network* network) { copyVar(depth[i]); } - network_cp->kernel = (Kernel**)malloc(sizeof(Kernel*)*size); - for (int i=0; i < size; i++) { + network_cp->kernel = (Kernel**)malloc(sizeof(Kernel*)*(size-1)); + for (int i=0; i < size-1; i++) { network_cp->kernel[i] = (Kernel*)malloc(sizeof(Kernel)); if (!network->kernel[i]->nn && !network->kernel[i]->cnn) { // Cas de la couche de linéarisation copyVar(kernel[i]->activation);