neuralNetwork Test bis auf den ersten test passts
This commit is contained in:
parent
19e402ae35
commit
ca36b9d062
@ -170,7 +170,12 @@ 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 = {NULL, 0, 0};
|
||||||
|
// Explizite Initialisierung verwenden, um die Feldreihenfolge in matrix.h zu umgehen:
|
||||||
|
Matrix matrix;
|
||||||
|
matrix.buffer = NULL;
|
||||||
|
matrix.rows = 0;
|
||||||
|
matrix.cols = 0;
|
||||||
|
|
||||||
if(count > 0 && images != NULL)
|
if(count > 0 && images != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,10 +5,52 @@
|
|||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "neuralNetwork.h"
|
#include "neuralNetwork.h"
|
||||||
|
|
||||||
|
// Define the file header string as used in neuralNetwork.c
|
||||||
|
#define FILE_HEADER_STRING "__info2_neural_network_file_format__"
|
||||||
|
|
||||||
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"); // Binärmodus zum Schreiben öffnen
|
||||||
|
|
||||||
|
if (file != NULL)
|
||||||
|
{
|
||||||
|
// 1. Identifikationstag schreiben
|
||||||
|
const char *fileTag = FILE_HEADER_STRING;
|
||||||
|
fwrite(fileTag, sizeof(char), strlen(fileTag), file);
|
||||||
|
|
||||||
|
// 2. Schichten (Layer) sequenziell schreiben
|
||||||
|
for (unsigned int i = 0; i < nn.numberOfLayers; i++)
|
||||||
|
{
|
||||||
|
const Layer currentLayer = nn.layers[i];
|
||||||
|
|
||||||
|
unsigned int inputDimension = currentLayer.weights.cols;
|
||||||
|
unsigned int outputDimension = currentLayer.weights.rows;
|
||||||
|
|
||||||
|
// Schreibe Input Dimension. Wichtig: Nutze sizeof(int)
|
||||||
|
// da readDimension in neuralNetwork.c in einen int liest.
|
||||||
|
fwrite(&inputDimension, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
// Schreibe Output Dimension.
|
||||||
|
fwrite(&outputDimension, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
// Schreibe Gewichtsmatrix (Weights) Daten
|
||||||
|
size_t numWeights = currentLayer.weights.rows * currentLayer.weights.cols;
|
||||||
|
fwrite(currentLayer.weights.buffer, sizeof(MatrixType), numWeights, file);
|
||||||
|
|
||||||
|
// Schreibe Biasmatrix (Biases) Daten
|
||||||
|
size_t numBiases = currentLayer.biases.rows * currentLayer.biases.cols;
|
||||||
|
fwrite(currentLayer.biases.buffer, sizeof(MatrixType), numBiases, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Ende des Modells signalisieren
|
||||||
|
unsigned int zero = 0;
|
||||||
|
// Wichtig: Auch hier sizeof(int) verwenden
|
||||||
|
fwrite(&zero, sizeof(int), 1, file); // Input Dimension = 0
|
||||||
|
fwrite(&zero, sizeof(int), 1, file); // Output Dimension = 0
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user