diff --git a/neuralNetwork.c b/neuralNetwork.c index 1e9dce8..27f9150 100644 --- a/neuralNetwork.c +++ b/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}; //hier evtl Null auf int casten? + Matrix matrix = {0, 0, NULL}; //hier evtl Null auf int casten? if(count > 0 && images != NULL) { diff --git a/neuralNetworkTests.c b/neuralNetworkTests.c index 21ab370..8155a9e 100644 --- a/neuralNetworkTests.c +++ b/neuralNetworkTests.c @@ -8,7 +8,42 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) { - // TODO + FILE *file = fopen(path, "wb"); + + if (file == NULL) { + return; + } + + // 1. Header schreiben + const char *fileTag = "__info2_neural_network_file_format__"; + fwrite(fileTag, sizeof(char), strlen(fileTag), file); + + // 2. Alle Schichten schreiben + for (unsigned int i = 0; i < nn.numberOfLayers; i++) { + // NUR bei der ERSTEN Schicht: Input-Dimension schreiben + if (i == 0) { + int inputDim = nn.layers[i].weights.cols; + fwrite(&inputDim, sizeof(int), 1, file); + } + + // Output-Dimension (= Anzahl Zeilen der Gewichtsmatrix) + int outputDim = nn.layers[i].weights.rows; + fwrite(&outputDim, sizeof(int), 1, file); + + // Gewichtsmatrix schreiben (alle Werte) + int weightCount = nn.layers[i].weights.rows * nn.layers[i].weights.cols; + fwrite(nn.layers[i].weights.buffer, sizeof(MatrixType), weightCount, file); + + // Bias-Matrix schreiben (alle Werte) + int biasCount = nn.layers[i].biases.rows * nn.layers[i].biases.cols; + fwrite(nn.layers[i].biases.buffer, sizeof(MatrixType), biasCount, file); + } + + // 3. Terminator schreiben (outputDimension = 0 zum Stoppen) + int terminator = 0; + fwrite(&terminator, sizeof(int), 1, file); + + fclose(file); } void test_loadModelReturnsCorrectNumberOfLayers(void)