forked from freudenreichan/info2Praktikum-NeuronalesNetz
NNTest nur noch predict-Fehler
This commit is contained in:
parent
86359bb37f
commit
8c2ed38abf
3
matrix.c
3
matrix.c
@ -8,9 +8,10 @@
|
|||||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||||
{
|
{
|
||||||
Matrix matrix;
|
Matrix matrix;
|
||||||
|
matrix.buffer = NULL;
|
||||||
matrix.rows = 0;
|
matrix.rows = 0;
|
||||||
matrix.cols = 0;
|
matrix.cols = 0;
|
||||||
matrix.buffer = NULL;
|
|
||||||
|
|
||||||
// Wenn die Dimensionen gültig sind, Speicher reservieren
|
// Wenn die Dimensionen gültig sind, Speicher reservieren
|
||||||
if (rows > 0 && cols > 0)
|
if (rows > 0 && cols > 0)
|
||||||
|
|||||||
3
matrix.h
3
matrix.h
@ -8,9 +8,10 @@ typedef float MatrixType;
|
|||||||
// TODO Matrixtyp definieren
|
// TODO Matrixtyp definieren
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
MatrixType *buffer;
|
||||||
unsigned int rows;
|
unsigned int rows;
|
||||||
unsigned int cols;
|
unsigned int cols;
|
||||||
MatrixType *buffer;
|
|
||||||
} Matrix;
|
} Matrix;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,47 @@
|
|||||||
|
|
||||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO : Fehlerbehandlung
|
||||||
|
FILE *file = fopen(path, "wb");
|
||||||
|
if (!file) {
|
||||||
|
perror("Fehler beim Öffnen der Datei");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *header = "__info2_neural_network_file_format__";
|
||||||
|
fwrite(header, sizeof(char), strlen(header), file);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < nn.numberOfLayers; i++) {
|
||||||
|
Layer layer = nn.layers[i];
|
||||||
|
|
||||||
|
unsigned int inputDim = (i == 0) ? layer.weights.cols : 0; // nur beim ersten Layer
|
||||||
|
unsigned int outputDim = layer.weights.rows;
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
// erstes Layer: inputDim und outputDim schreiben
|
||||||
|
fwrite(&inputDim, sizeof(unsigned int), 1, file);
|
||||||
|
fwrite(&outputDim, sizeof(unsigned int), 1, file);
|
||||||
|
} else {
|
||||||
|
// nur outputDim für weitere Layer
|
||||||
|
fwrite(&outputDim, sizeof(unsigned int), 1, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
fwrite(layer.weights.buffer, sizeof(MatrixType), layer.weights.rows * layer.weights.cols, file);
|
||||||
|
fwrite(layer.biases.buffer, sizeof(MatrixType), layer.biases.rows * layer.biases.cols, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int zero = 0;
|
||||||
|
fwrite(&zero, sizeof(unsigned int), 1, file);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
// Debug
|
||||||
|
printf("prepareNeuralNetworkFile: Datei '%s' erstellt mit %u Layer(n)\n", path, nn.numberOfLayers);
|
||||||
|
for (unsigned int i = 0; i < nn.numberOfLayers; i++) {
|
||||||
|
Layer layer = nn.layers[i];
|
||||||
|
printf("Layer %u: weights (%u x %u), biases (%u x %u)\n",
|
||||||
|
i, layer.weights.rows, layer.weights.cols, layer.biases.rows, layer.biases.cols);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user