forked from freudenreichan/info2Praktikum-NeuronalesNetz
neuralNetwork.c
neuralNetworkTests.c check
This commit is contained in:
parent
8d4ee4cc4e
commit
8ceb081ffe
@ -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}; //hier evtl Null auf int casten?
|
Matrix matrix = {0, 0, NULL}; //hier evtl Null auf int casten?
|
||||||
|
|
||||||
if(count > 0 && images != NULL)
|
if(count > 0 && images != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,7 +8,42 @@
|
|||||||
|
|
||||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||||
{
|
{
|
||||||
// TODO
|
FILE *file = fopen(path, "wb");
|
||||||
|
|
||||||
|
if (file == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Header schreiben
|
||||||
|
const char *fileTag = "__info2_neural_network_file_format__";
|
||||||
|
fwrite(fileTag, sizeof(char), strlen(fileTag), file);
|
||||||
|
|
||||||
|
// 2. Alle Schichten schreiben
|
||||||
|
for (unsigned int i = 0; i < nn.numberOfLayers; i++) {
|
||||||
|
// NUR bei der ERSTEN Schicht: Input-Dimension schreiben
|
||||||
|
if (i == 0) {
|
||||||
|
int inputDim = nn.layers[i].weights.cols;
|
||||||
|
fwrite(&inputDim, sizeof(int), 1, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output-Dimension (= Anzahl Zeilen der Gewichtsmatrix)
|
||||||
|
int outputDim = nn.layers[i].weights.rows;
|
||||||
|
fwrite(&outputDim, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
// Gewichtsmatrix schreiben (alle Werte)
|
||||||
|
int weightCount = nn.layers[i].weights.rows * nn.layers[i].weights.cols;
|
||||||
|
fwrite(nn.layers[i].weights.buffer, sizeof(MatrixType), weightCount, file);
|
||||||
|
|
||||||
|
// Bias-Matrix schreiben (alle Werte)
|
||||||
|
int biasCount = nn.layers[i].biases.rows * nn.layers[i].biases.cols;
|
||||||
|
fwrite(nn.layers[i].biases.buffer, sizeof(MatrixType), biasCount, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Terminator schreiben (outputDimension = 0 zum Stoppen)
|
||||||
|
int terminator = 0;
|
||||||
|
fwrite(&terminator, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user