forked from freudenreichan/info2Praktikum-NeuronalesNetz
prepare datei fertig
This commit is contained in:
parent
4ad5b4f595
commit
7ae0fa1d4a
@ -7,7 +7,45 @@
|
||||
|
||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||
{
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) return;
|
||||
|
||||
const char *tag = "__info2_neural_network_file_format__";
|
||||
fwrite(tag, 1, strlen(tag), f);
|
||||
|
||||
if (nn.numberOfLayers == 0) {
|
||||
fclose(f);
|
||||
return;
|
||||
} // Alle Tests prüfen
|
||||
|
||||
|
||||
int input = nn.layers[0].weights.cols;
|
||||
int output = nn.layers[0].weights.rows;
|
||||
|
||||
fwrite(&input, sizeof(int), 1, f);
|
||||
fwrite(&output, sizeof(int), 1, f);
|
||||
|
||||
for (int i = 0; i < nn.numberOfLayers; i++)
|
||||
{
|
||||
const Layer *layer = &nn.layers[i];
|
||||
int out = layer->weights.rows;
|
||||
int in = layer->weights.cols;
|
||||
|
||||
|
||||
fwrite(layer->weights.buffer, sizeof(MatrixType), out * in, f);
|
||||
|
||||
|
||||
fwrite(layer->biases.buffer, sizeof(MatrixType), out * 1, f);
|
||||
|
||||
|
||||
if (i + 1 < nn.numberOfLayers)
|
||||
{
|
||||
int nextOut = nn.layers[i + 1].weights.rows;
|
||||
fwrite(&nextOut, sizeof(int), 1, f);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user