Erste Version neuralNetworksTests.c
This commit is contained in:
parent
f2b748a9c5
commit
734b72d346
@ -9,6 +9,40 @@
|
|||||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
|
FILE *f = fopen(path, "wb");
|
||||||
|
if (!f) return;
|
||||||
|
|
||||||
|
fwrite(FILE_HEADER_STRING, sizeof(char), strlen(FILE_HEADER_STRING), f);
|
||||||
|
|
||||||
|
int inputDim = nn.layers[0].weights.cols;
|
||||||
|
int outputDim = nn.layers[0].weights.rows;
|
||||||
|
|
||||||
|
fwrite(&inputDim, sizeof(int), 1, f);
|
||||||
|
fwrite(&outputDim, sizeof(int), 1, f);
|
||||||
|
|
||||||
|
for (int i = 0; i < nn.numberOfLayers; i++)
|
||||||
|
{
|
||||||
|
Matrix weights = nn.layers[i].weights;
|
||||||
|
Matrix biases = nn.layers[i].biases;
|
||||||
|
|
||||||
|
int numWeightValues = weights.rows * weights.cols;
|
||||||
|
int numBiasValues = biases.rows * biases.cols;
|
||||||
|
|
||||||
|
fwrite(weights.buffer, sizeof(MatrixType), numWeightValues, f);
|
||||||
|
fwrite(biases.buffer, sizeof(MatrixType), numBiasValues, f);
|
||||||
|
|
||||||
|
if (i < nn.numberOfLayers - 1)
|
||||||
|
{
|
||||||
|
int nextOutputDim = nn.layers[i + 1].weights.rows;
|
||||||
|
fwrite(&nextOutputDim, sizeof(int), 1, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int endMarker = 0;
|
||||||
|
fwrite(&endMarker, sizeof(int), 1, f);
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user