complete code

This commit is contained in:
Your Name 2026-05-15 11:11:35 +02:00
parent 43edb7de81
commit 5b295c52d1
6 changed files with 37 additions and 3 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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)
{

View File

@ -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
}

BIN
runImageInputTests Executable file

Binary file not shown.

BIN
runNeuralNetworkTests Executable file

Binary file not shown.