NeuralNetwork.tests.c eingefuegt
This commit is contained in:
parent
74e7a21999
commit
cc54d4e1dc
@ -4,13 +4,47 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "neuralNetwork.h"
|
#include "neuralNetwork.h"
|
||||||
|
//Dateischichten sind in neuralNetwork.h definiert
|
||||||
|
// Dateiname: __info2_neural_network_file_format__
|
||||||
|
|
||||||
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) return;
|
||||||
|
|
||||||
|
// Header schreiben
|
||||||
|
fwrite(FILE_HEADER_STRING, 1, strlen(FILE_HEADER_STRING), file);
|
||||||
|
|
||||||
|
// Anzahl Layer schreiben
|
||||||
|
uint32_t nLayers = nn.numberOfLayers;
|
||||||
|
fwrite(&nLayers, sizeof(uint32_t), 1, file);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < nLayers; i++) {
|
||||||
|
Layer layer = nn.layers[i];
|
||||||
|
|
||||||
|
// Weights-Dimensionen
|
||||||
|
uint32_t rW = layer.weights.rows;
|
||||||
|
uint32_t cW = layer.weights.cols;
|
||||||
|
fwrite(&rW, sizeof(uint32_t), 1, file);
|
||||||
|
fwrite(&cW, sizeof(uint32_t), 1, file);
|
||||||
|
|
||||||
|
// Weights-Werte
|
||||||
|
fwrite(layer.weights.buffer, sizeof(MatrixType), rW * cW, file);
|
||||||
|
|
||||||
|
// Bias-Dimensionen
|
||||||
|
uint32_t rB = layer.biases.rows;
|
||||||
|
uint32_t cB = layer.biases.cols;
|
||||||
|
fwrite(&rB, sizeof(uint32_t), 1, file);
|
||||||
|
fwrite(&cB, sizeof(uint32_t), 1, file);
|
||||||
|
|
||||||
|
// Bias-Werte
|
||||||
|
fwrite(layer.biases.buffer, sizeof(MatrixType), rB * cB, 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