diff --git a/imageInput.c b/imageInput.c index 0dd3b4c..37a21dc 100644 --- a/imageInput.c +++ b/imageInput.c @@ -49,7 +49,10 @@ GrayScaleImageSeries *readImages(const char *path) } unsigned short numberOfImages, width, height; - readFileHeader(file, &numberOfImages, &width, &height); // Hilfsfunktion von oben + if (!readFileHeader(file, &numberOfImages, &width, &height)) { + fclose(file); + return NULL; + } GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries)); // Speicher in Serie-Struktur reservieren if (series == NULL) { // kann nicht angelegt werden diff --git a/matrix.c b/matrix.c index 67c64ce..d2d725f 100644 --- a/matrix.c +++ b/matrix.c @@ -99,6 +99,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) } for (unsigned int i =0; i < resultRows; ++i){ for (unsigned int j =0; j< resultCols; ++j){ + // compute dot product of row i from matrix1 and column j from matrix2 MatrixType sum = 0.0; for (unsigned int k =0; k< matrix1.cols; ++k){ MatrixType val1 =getMatrixAt(matrix1, i,k); @@ -107,7 +108,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) } - unsigned int resultIndex = i * resultCols + j; + unsigned int resultIndex = i * resultCols + j; // store the result resultBuffer [resultIndex] = sum; } } diff --git a/neuralNetwork.c b/neuralNetwork.c index bd8f164..30e6e4f 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}; + Matrix matrix = {0, 0, NULL}; if(count > 0 && images != NULL) { diff --git a/neuralNetworkTests.c b/neuralNetworkTests.c index 21ab370..0d41072 100644 --- a/neuralNetworkTests.c +++ b/neuralNetworkTests.c @@ -8,6 +8,36 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) { + FILE *file = fopen(path, "wb"); + + if (file != NULL){ + const char *fileTag = "__info2_neural_network_file_format__"; // write the file header + fwrite(fileTag, sizeof(char), strlen(fileTag), file); + for (unsigned int i =0; i< nn.numberOfLayers; i++){ //write each layer to the file + Layer layer = nn.layers[i]; + int inputDimension = layer.weights.cols; // extract inputDimension from weights + int outputDimension = layer.weights.rows; // extract outputDimension from weights + + // For the first layer, write both inputDimension and outputDimension + // For subsequent layers, only write outputDimension (inputDimension = previous outputDimension) + if (i == 0) { + fwrite(&inputDimension, sizeof(int), 1, file); + } + fwrite(&outputDimension, sizeof(int), 1, file); + + // write weights matrix data + int weightsElementcount= layer.weights.rows *layer.weights.cols; + fwrite(layer.weights.buffer, sizeof(MatrixType), weightsElementcount, file); + + //write biases matrix data + int biasesElementCount = layer.biases.rows *layer.biases.cols; + fwrite(layer.biases.buffer, sizeof (MatrixType), biasesElementCount, file); + + } + int endMarker = 0; // write end marker (0) to signal no more layers + fwrite(&endMarker, sizeof(int), 1, file); + fclose(file); // close the file + } // TODO } diff --git a/runImageInputTests b/runImageInputTests new file mode 100755 index 0000000..c5570eb Binary files /dev/null and b/runImageInputTests differ diff --git a/runNeuralNetworkTests b/runNeuralNetworkTests new file mode 100755 index 0000000..6ef9579 Binary files /dev/null and b/runNeuralNetworkTests differ