Test feinschliff
This commit is contained in:
1 parent
aa8ba9db4a
commit
aba8d54204
2 files changed
+13
-3
No files matched your search
@@ -170,7 +170,7 @@ NeuralNetwork loadModel(const char *path)
|
|||||||
|
|
||||||
static Matrix imageBatchToMatrixOfImageVectors(const GrayScaleImage images[], unsigned int count)
|
static Matrix imageBatchToMatrixOfImageVectors(const GrayScaleImage images[], unsigned int count)
|
||||||
{
|
{
|
||||||
Matrix matrix = {NULL, 0, 0};
|
Matrix matrix = {0, 0, NULL};
|
||||||
|
|
||||||
if(count > 0 && images != NULL)
|
if(count > 0 && images != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
|
//Datei zum binaeren schreiben oeffnen
|
||||||
FILE *file = fopen(path, "wb");
|
FILE *file = fopen(path, "wb");
|
||||||
|
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
@@ -16,20 +18,26 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *header = " __info2_neural_network_file_format__";
|
//Header schreiben, loadModel prüft nach String
|
||||||
|
const char *header = "__info2_neural_network_file_format__";
|
||||||
fwrite(header, sizeof(char), strlen(header), file);
|
fwrite(header, sizeof(char), strlen(header), file);
|
||||||
|
|
||||||
|
//Nur wenn mind. 1 layer da ist
|
||||||
if (nn.numberOfLayers > 0)
|
if (nn.numberOfLayers > 0)
|
||||||
{
|
{
|
||||||
|
//Format entspricht anzahl der cols der Matrix des 1ten Layers
|
||||||
int inputDimension = nn.layers[0].weights.cols;
|
int inputDimension = nn.layers[0].weights.cols;
|
||||||
fwrite(&inputDimension, sizeof(int), 1, file);
|
fwrite(&inputDimension, sizeof(int), 1, file);
|
||||||
|
|
||||||
|
//Layer nacheinander in Datei schreiben
|
||||||
for (unsigned int i = 0; i < nn.numberOfLayers; i++)
|
for (unsigned int i = 0; i < nn.numberOfLayers; i++)
|
||||||
{
|
{
|
||||||
Layer layer = nn.layers[i];
|
Layer layer = nn.layers[i];
|
||||||
|
|
||||||
|
//outputDimension entspricht Zeilenzahl seiner Matrix
|
||||||
int outputDimension = layer.weights.rows;
|
int outputDimension = layer.weights.rows;
|
||||||
|
|
||||||
|
//outputDim. speichern
|
||||||
fwrite(&outputDimension, sizeof(int), 1, file);
|
fwrite(&outputDimension, sizeof(int), 1, file);
|
||||||
|
|
||||||
int weightCount = layer.weights.rows * layer.weights.cols;
|
int weightCount = layer.weights.rows * layer.weights.cols;
|
||||||
@@ -41,11 +49,13 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
|||||||
fwrite(layer.biases.buffer, sizeof(MatrixType), biasCount, file);
|
fwrite(layer.biases.buffer, sizeof(MatrixType), biasCount, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Abbruchkriterium für loadModel
|
||||||
int endMarker = 0;
|
int endMarker = 0;
|
||||||
|
|
||||||
fwrite(&endMarker, sizeof(int), 1, file);
|
fwrite(&endMarker, sizeof(int), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Datei schließen
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user