Added some stuff to prepareNeuralNetworkFile function

This commit is contained in:
Lukas Weber 2025-11-26 12:13:19 +01:00
parent cfb3848fe2
commit bb96c8f78a
2 changed files with 11 additions and 3 deletions

View File

@ -170,7 +170,7 @@ NeuralNetwork loadModel(const char *path)
static Matrix imageBatchToMatrixOfImageVectors(const GrayScaleImage images[], unsigned int count) static Matrix imageBatchToMatrixOfImageVectors(const GrayScaleImage images[], unsigned int count)
{ {
Matrix matrix = {NULL, 0, 0}; Matrix matrix = {0, 0, NULL}; // TODO changed this line to fit our functionality
if(count > 0 && images != NULL) if(count > 0 && images != NULL)
{ {

View File

@ -9,12 +9,20 @@
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
{ {
// TODO // TODO
FILE file = fopen(path, "wb"); FILE* file = fopen(path, "wb");
fwrite(path, sizeof(const char), 24, file); fwrite(path, sizeof(const char), 24, file);
fwrite(&(nn.nmberOfLayers), sizeof(unsigned int), 1, file);
for(int i = 0; i < nn.numberOfLayers; i++) { for(int i = 0; i < nn.numberOfLayers; i++) {
//write everything to do with weights
fwrite(&(nn.layers[i].weights.rows), sizeof(unsigned int), 1, file);
fwrite(&(nn.layers[i].weights.cols), sizeof(unsigned int), 1, file);
fwrite(nn.layers[i].weights.buffer, sizeof(MatrixType), nn.layers[i].weights.rows * nn.layers[i].weights.cols, file); fwrite(nn.layers[i].weights.buffer, sizeof(MatrixType), nn.layers[i].weights.rows * nn.layers[i].weights.cols, file);
//write everything to do with biases
fwrite(&(nn.layers[i].biases.rows), sizeof(unsigned int), 1, file);
fwrite(&(nn.layers[i].biases.cols), sizeof(unsigned int), 1, file);
fwrite(nn.layers[i].biases.buffer, sizeof(MatrixType), nn.layers[i].biases.rows * nn.layers[i].biases.cols, file); fwrite(nn.layers[i].biases.buffer, sizeof(MatrixType), nn.layers[i].biases.rows * nn.layers[i].biases.cols, file);
fwrite(nn.layers[i].activation->buffer, sizeof(MatrixType), nn.layers[i].activation->rows * nn.layers[i].activation->cols, file); }
} }
void test_loadModelReturnsCorrectNumberOfLayers(void) void test_loadModelReturnsCorrectNumberOfLayers(void)