prepareNeuralNetworkFile
This commit is contained in:
1 parent
b6ae8d17b1
commit
aa8ba9db4a
1 file changed
+39
@@ -9,6 +9,45 @@
|
|||||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
|
FILE *file = fopen(path, "wb");
|
||||||
|
|
||||||
|
if (file == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *header = " __info2_neural_network_file_format__";
|
||||||
|
fwrite(header, sizeof(char), strlen(header), file);
|
||||||
|
|
||||||
|
if (nn.numberOfLayers > 0)
|
||||||
|
{
|
||||||
|
int inputDimension = nn.layers[0].weights.cols;
|
||||||
|
fwrite(&inputDimension, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < nn.numberOfLayers; i++)
|
||||||
|
{
|
||||||
|
Layer layer = nn.layers[i];
|
||||||
|
|
||||||
|
int outputDimension = layer.weights.rows;
|
||||||
|
|
||||||
|
fwrite(&outputDimension, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
int weightCount = layer.weights.rows * layer.weights.cols;
|
||||||
|
|
||||||
|
fwrite(layer.weights.buffer, sizeof(MatrixType), weightCount, file);
|
||||||
|
|
||||||
|
int biasCount = layer.biases.rows * layer.biases.cols;
|
||||||
|
|
||||||
|
fwrite(layer.biases.buffer, sizeof(MatrixType), biasCount, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
int endMarker = 0;
|
||||||
|
|
||||||
|
fwrite(&endMarker, sizeof(int), 1, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
|
|||||||
Reference in new issue
Block a user