From b6ae8d17b106107d1c3b744492a2bccb7d89bd5d Mon Sep 17 00:00:00 2001 From: Baeuml Date: Thu, 29 Oct 2026 10:12:16 +0100 Subject: [PATCH 1/5] test --- Startcode/imageInput.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Startcode/imageInput.c b/Startcode/imageInput.c index bb30de1..838c65a 100644 --- a/Startcode/imageInput.c +++ b/Startcode/imageInput.c @@ -2,7 +2,7 @@ #include #include #include "imageInput.h" - +//test #define BUFFER_SIZE 100 #define FILE_HEADER_STRING "__info2_image_file_format__" From aa8ba9db4ab79d284b6ef11945ffec8c9cbf289f Mon Sep 17 00:00:00 2001 From: Baeuml Date: Tue, 10 Nov 2026 21:28:26 +0100 Subject: [PATCH 2/5] prepareNeuralNetworkFile --- Startcode/neuralNetworkTests.c | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Startcode/neuralNetworkTests.c b/Startcode/neuralNetworkTests.c index 21ab370..9b47149 100644 --- a/Startcode/neuralNetworkTests.c +++ b/Startcode/neuralNetworkTests.c @@ -9,6 +9,45 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) { // TODO + FILE *file = fopen(path, "wb"); + + if (file == NULL) + { + return; + } + + const char *header = " __info2_neural_network_file_format__"; + fwrite(header, sizeof(char), strlen(header), file); + + if (nn.numberOfLayers > 0) + { + int inputDimension = nn.layers[0].weights.cols; + fwrite(&inputDimension, sizeof(int), 1, file); + + for (unsigned int i = 0; i < nn.numberOfLayers; i++) + { + Layer layer = nn.layers[i]; + + int outputDimension = layer.weights.rows; + + fwrite(&outputDimension, sizeof(int), 1, file); + + int weightCount = layer.weights.rows * layer.weights.cols; + + fwrite(layer.weights.buffer, sizeof(MatrixType), weightCount, file); + + int biasCount = layer.biases.rows * layer.biases.cols; + + fwrite(layer.biases.buffer, sizeof(MatrixType), biasCount, file); + } + + int endMarker = 0; + + fwrite(&endMarker, sizeof(int), 1, file); + } + + fclose(file); + } void test_loadModelReturnsCorrectNumberOfLayers(void) From aba8d5420404cc9b78c4c100ede4749864bdb126 Mon Sep 17 00:00:00 2001 From: Baeuml Date: Tue, 10 Nov 2026 22:04:53 +0100 Subject: [PATCH 3/5] Test feinschliff --- Startcode/neuralNetwork.c | 2 +- Startcode/neuralNetworkTests.c | 14 ++++++++++++-- 2 files changed, 13 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 9b47149..5fa71f6 100644 --- a/Startcode/neuralNetworkTests.c +++ b/Startcode/neuralNetworkTests.c @@ -9,6 +9,8 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) { // TODO + + //Datei zum binaeren schreiben oeffnen FILE *file = fopen(path, "wb"); if (file == NULL) @@ -16,20 +18,26 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) return; } - const char *header = " __info2_neural_network_file_format__"; + //Header schreiben, loadModel prüft nach String + const char *header = "__info2_neural_network_file_format__"; fwrite(header, sizeof(char), strlen(header), file); + //Nur wenn mind. 1 layer da ist if (nn.numberOfLayers > 0) { + //Format entspricht anzahl der cols der Matrix des 1ten Layers int inputDimension = nn.layers[0].weights.cols; fwrite(&inputDimension, sizeof(int), 1, file); + //Layer nacheinander in Datei schreiben for (unsigned int i = 0; i < nn.numberOfLayers; i++) { Layer layer = nn.layers[i]; + //outputDimension entspricht Zeilenzahl seiner Matrix int outputDimension = layer.weights.rows; - + + //outputDim. speichern fwrite(&outputDimension, sizeof(int), 1, file); int weightCount = layer.weights.rows * layer.weights.cols; @@ -41,11 +49,13 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) fwrite(layer.biases.buffer, sizeof(MatrixType), biasCount, file); } + //Abbruchkriterium für loadModel int endMarker = 0; fwrite(&endMarker, sizeof(int), 1, file); } + //Datei schließen fclose(file); } From eb8db3856a798869b799dacd353380ac5611de51 Mon Sep 17 00:00:00 2001 From: Baeuml Date: Wed, 11 Nov 2026 00:37:27 +0100 Subject: [PATCH 4/5] verbesserung --- Startcode/neuralNetworkTests.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Startcode/neuralNetworkTests.c b/Startcode/neuralNetworkTests.c index 5fa71f6..612a737 100644 --- a/Startcode/neuralNetworkTests.c +++ b/Startcode/neuralNetworkTests.c @@ -22,7 +22,7 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) const char *header = "__info2_neural_network_file_format__"; fwrite(header, sizeof(char), strlen(header), file); - //Nur wenn mind. 1 layer da ist + //Prüfen ob Layer existieren if (nn.numberOfLayers > 0) { //Format entspricht anzahl der cols der Matrix des 1ten Layers @@ -50,9 +50,9 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) } //Abbruchkriterium für loadModel - int endMarker = 0; + int ende= 0; - fwrite(&endMarker, sizeof(int), 1, file); + fwrite(&ende, sizeof(int), 1, file); } //Datei schließen From 741486560822a4063a81c2153584c5719fb4bb35 Mon Sep 17 00:00:00 2001 From: Baeuml Date: Wed, 11 Nov 2026 00:41:22 +0100 Subject: [PATCH 5/5] kommentare --- Startcode/neuralNetworkTests.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Startcode/neuralNetworkTests.c b/Startcode/neuralNetworkTests.c index 612a737..45d6ccd 100644 --- a/Startcode/neuralNetworkTests.c +++ b/Startcode/neuralNetworkTests.c @@ -40,12 +40,16 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) //outputDim. speichern fwrite(&outputDimension, sizeof(int), 1, file); + //weight werte berechnen int weightCount = layer.weights.rows * layer.weights.cols; + //Matrix speichern fwrite(layer.weights.buffer, sizeof(MatrixType), weightCount, file); + //bias berechnen int biasCount = layer.biases.rows * layer.biases.cols; + //bias speichern fwrite(layer.biases.buffer, sizeof(MatrixType), biasCount, file); }