Version 1; prepare Funktion geschrieben
This commit is contained in:
parent
b8510c82da
commit
ae761afb00
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"unity.h": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,8 +8,52 @@
|
|||||||
|
|
||||||
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 (!fiile)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schreibe den Datei-Tag
|
||||||
|
const char tag = "info2_neural_network_file_format";
|
||||||
|
fwrite(tag, 1, strlen(tag), file);
|
||||||
|
|
||||||
|
// Überprüfe, ob es Layer gibt
|
||||||
|
if (nn.numberOfLayers == 0)
|
||||||
|
{
|
||||||
|
fclose(file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schreibe die Eingabe- und Ausgabegrößen des Netzwerks
|
||||||
|
int input = nn.layers[0].weights.cols;
|
||||||
|
int output = nn.layers[0].weights.rows;
|
||||||
|
|
||||||
|
fwrite(&input, sizeof(int), 1, file);
|
||||||
|
fwrite(&output, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
// Schreibe die Layer-Daten
|
||||||
|
for (int i = 0; i < nn.numberOfLayers; i++)
|
||||||
|
{
|
||||||
|
const Layerlayer = &nn.layers[i];
|
||||||
|
int out = layer->weights.rows;
|
||||||
|
int in = layer->weights.cols;
|
||||||
|
|
||||||
|
|
||||||
|
fwrite(layer->weights.buffer, sizeof(MatrixType), out * in, file);
|
||||||
|
|
||||||
|
|
||||||
|
fwrite(layer->biases.buffer, sizeof(MatrixType), out * 1, file);
|
||||||
|
|
||||||
|
if (i + 1 < nn.numberOfLayers)
|
||||||
|
{
|
||||||
|
int nextOut = nn.layers[i + 1].weights.rows;
|
||||||
|
fwrite(&nextOut, sizeof(int), 1, file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user