From 16a9cafc18d3282a11531323ab11fc828a3ac07a Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 10 Feb 2023 14:55:08 +0100 Subject: [PATCH] Update neuron_io.c to save larger networks --- .vscode/launch.json | 29 +++++++++++++++++++++++++++++ src/cnn/neuron_io.c | 18 +++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 9747aea..d4aa6a1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -174,6 +174,35 @@ ], "preLaunchTask": "build-cnn" }, + { + "name": "cnn/main save-network", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/cnn-main", + "args": [ + "train", + "--dataset", + "jpg", + "--datadir", + "data/50States10K/test", + "--epochs", + "0" + ], + "stopAtEntry": true, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": false + } + ], + "preLaunchTask": "build-cnn" + }, { "name": "cnn/main dev-conv", "type": "cppdbg", diff --git a/src/cnn/neuron_io.c b/src/cnn/neuron_io.c index 8083942..f42a605 100644 --- a/src/cnn/neuron_io.c +++ b/src/cnn/neuron_io.c @@ -81,16 +81,20 @@ void write_couche(Network* network, int indice_couche, int type_couche, FILE* pt fwrite(pre_buffer, sizeof(pre_buffer), 1, ptr); // Écriture du corps - float buffer[cnn->columns*(cnn->k_size*cnn->k_size*cnn->rows+output_dim*output_dim)]; - + // We need to split in small buffers to keep some free memory in the computer for (int i=0; i < cnn->columns; i++) { + indice_buffer = 0; + float buffer[output_dim*output_dim]; for (int j=0; j < output_dim; j++) { for (int k=0; k < output_dim; k++) { bufferAdd(cnn->bias[i][j][k]); } } + fwrite(buffer, sizeof(buffer), 1, ptr); } for (int i=0; i < cnn->rows; i++) { + indice_buffer = 0; + float buffer[cnn->columns*cnn->k_size*cnn->k_size]; for (int j=0; j < cnn->columns; j++) { for (int k=0; k < cnn->k_size; k++) { for (int l=0; l < cnn->k_size; l++) { @@ -98,8 +102,8 @@ void write_couche(Network* network, int indice_couche, int type_couche, FILE* pt } } } + fwrite(buffer, sizeof(buffer), 1, ptr); } - fwrite(buffer, sizeof(buffer), 1, ptr); } else if (type_couche == 1) { // Cas du NN Kernel_nn* nn = kernel->nn; @@ -112,16 +116,20 @@ void write_couche(Network* network, int indice_couche, int type_couche, FILE* pt fwrite(pre_buffer, sizeof(pre_buffer), 1, ptr); // Écriture du corps - float buffer[(1+nn->input_units)*nn->output_units]; + float buffer[nn->output_units]; for (int i=0; i < nn->output_units; i++) { bufferAdd(nn->bias[i]); } + fwrite(buffer, sizeof(buffer), 1, ptr); + for (int i=0; i < nn->input_units; i++) { + indice_buffer = 0; + float buffer[nn->output_units]; for (int j=0; j < nn->output_units; j++) { bufferAdd(nn->weights[i][j]); } + fwrite(buffer, sizeof(buffer), 1, ptr); } - fwrite(buffer, sizeof(buffer), 1, ptr); } else if (type_couche == 2) { // Cas du Pooling Layer uint32_t pre_buffer[2]; pre_buffer[0] = kernel->linearisation;