Compare commits

..

No commits in common. "bbb0ea1cf5c8fea4f988f661450056f0979463d7" and "633ee723f47ac168958375dc3ded87b23efe4d67" have entirely different histories.

View File

@ -5,46 +5,10 @@
#include "unity.h"
#include "neuralNetwork.h"
static void writeLayer(FILE *file, const Matrix weights, const Matrix biases, unsigned int inputDim)
{
unsigned int outputDim = (unsigned int)weights.rows;
fwrite(&outputDim, sizeof(unsigned int), 1, file);
if (weights.buffer != NULL)
fwrite(weights.buffer, sizeof(MatrixType), outputDim * inputDim, file);
if (biases.buffer != NULL)
fwrite(biases.buffer, sizeof(MatrixType), outputDim, file);
}
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
{
FILE *file = fopen(path, "wb");
if (!file) return;
const char tag[] = "__info2_neural_network_file_format__";
fwrite(tag, sizeof(char), strlen(tag), file);
if (nn.numberOfLayers == 0)
{
unsigned int zero = 0;
fwrite(&zero, sizeof(unsigned int), 1, file);
fclose(file);
return;
}
unsigned int inputDim = (unsigned int)nn.layers[0].weights.cols;
fwrite(&inputDim, sizeof(unsigned int), 1, file);
for (int i = 0; i < nn.numberOfLayers; i++)
{
writeLayer(file, nn.layers[i].weights, nn.layers[i].biases, inputDim);
inputDim = (unsigned int)nn.layers[i].weights.rows;
}
unsigned int zero = 0;
fwrite(&zero, sizeof(unsigned int), 1, file);
fclose(file);
// TODO
}
void test_loadModelReturnsCorrectNumberOfLayers(void)