neuralNetworkTests
This commit is contained in:
parent
5dfce43fa1
commit
bf36733274
@ -6,11 +6,46 @@
|
|||||||
#include "neuralNetwork.h"
|
#include "neuralNetwork.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||||
{
|
{
|
||||||
// TODO
|
//öffnet die Datei in Binär zum schreiben
|
||||||
|
FILE *file = fopen(path, "wb");
|
||||||
|
if (!file) return;
|
||||||
|
//Fester Headerstring
|
||||||
|
const char *tag = "__info2_neural_network_file_format__";
|
||||||
|
fwrite(tag, sizeof(char), strlen(tag), file);
|
||||||
|
//Bestimmt die Eingabedimension
|
||||||
|
int inputDim = nn.layers[0].weights.cols;
|
||||||
|
fwrite(&inputDim, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < nn.numberOfLayers; i++) {
|
||||||
|
|
||||||
|
const Layer *L = &nn.layers[i];
|
||||||
|
const Matrix *W = &L->weights;
|
||||||
|
const Matrix *B = &L->biases;
|
||||||
|
|
||||||
|
int outputDim = W->rows;
|
||||||
|
fwrite(&outputDim, sizeof(int), 1, file);
|
||||||
|
//Anzahl der Weight-Werte
|
||||||
|
size_t weightCount = (size_t)(W->rows * W->cols);
|
||||||
|
fwrite(&weightCount, sizeof(size_t), 1, file);
|
||||||
|
//Anzahl der Bias-Werte
|
||||||
|
size_t biasCount = (size_t)(B->rows * B->cols);
|
||||||
|
fwrite(B->buffer, sizeof(MatrixType), biasCount, file);
|
||||||
|
|
||||||
|
inputDim = outputDim;
|
||||||
|
}
|
||||||
|
|
||||||
|
int zero = 0;
|
||||||
|
fwrite(&zero, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
{
|
{
|
||||||
const char *path = "some__nn_test_file.info2";
|
const char *path = "some__nn_test_file.info2";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user