From 833a4c3c79f7b0ecbe1184d55723446d7639e185 Mon Sep 17 00:00:00 2001 From: Alex Reece Date: Thu, 29 Oct 2026 15:21:35 +0100 Subject: [PATCH] prepareNeuralNetwork initial implementation --- Startcode/neuralNetwork.c | 2 +- Startcode/neuralNetworkTests.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Startcode/neuralNetwork.c b/Startcode/neuralNetwork.c index bd8f164..30e6e4f 100644 --- a/Startcode/neuralNetwork.c +++ b/Startcode/neuralNetwork.c @@ -170,7 +170,7 @@ NeuralNetwork loadModel(const char *path) static Matrix imageBatchToMatrixOfImageVectors(const GrayScaleImage images[], unsigned int count) { - Matrix matrix = {NULL, 0, 0}; + Matrix matrix = {0, 0, NULL}; if(count > 0 && images != NULL) { diff --git a/Startcode/neuralNetworkTests.c b/Startcode/neuralNetworkTests.c index 21ab370..dab12ab 100644 --- a/Startcode/neuralNetworkTests.c +++ b/Startcode/neuralNetworkTests.c @@ -4,11 +4,27 @@ #include #include "unity.h" #include "neuralNetwork.h" - +#define FILE_HEADER_STRING "__info2_neural_network_file_format__" static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) { - // TODO + FILE *fd = fopen(path, "wb"); + + if (fd == NULL) + return; + + fwrite(FILE_HEADER_STRING, sizeof(FILE_HEADER_STRING) - 1, 1, fd); + // fwrite(&nn, sizeof(nn), 1, fd); + fwrite(&(nn.layers[0].weights.cols), sizeof(nn.layers[0].weights.cols), 1, fd); + for (int i = 0; i < nn.numberOfLayers; ++i) + { + fwrite(&(nn.layers[i].weights.rows), sizeof(nn.layers[i].weights.rows), 1, fd); + fwrite(&(nn.layers[i].weights.buffer), sizeof(MatrixType) * nn.layers[i].weights.rows * nn.layers[i].weights.cols, 1, fd); + fwrite(&(nn.layers[i].biases.buffer), sizeof(MatrixType) * nn.layers[i].biases.rows, 1, fd); + } + const float zeroooooo = 0.0F; + fwrite(&zeroooooo, sizeof(MatrixType), 1, fd); + fclose(fd); } void test_loadModelReturnsCorrectNumberOfLayers(void)