forked from freudenreichan/info2Praktikum-NeuronalesNetz
neuralNetworkTests fertig
This commit is contained in:
1 parent
9468b6aea0
commit
47690eaa20
1 file changed
+14
-12
@@ -16,24 +16,26 @@ static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||
const char *fileTag = "__info2_neural_network_file_format__";
|
||||
|
||||
fwrite(fileTag, sizeof(char), strlen(fileTag), file);
|
||||
fwrite(&nn.numberOfLayers, sizeof(nn.numberOfLayers), 1, file);
|
||||
if(nn.numberOfLayers > 0){
|
||||
int dimension;
|
||||
|
||||
for(int i = 0; i < nn.numberOfLayers; i++){
|
||||
fwrite(&nn.layers[i].weights.rows, sizeof(nn.layers[i].weights.rows), 1, file);
|
||||
fwrite(&nn.layers[i].weights.cols, sizeof(nn.layers[i].weights.cols), 1, file);
|
||||
dimension = nn.layers[0].weights.cols;
|
||||
fwrite(&dimension, sizeof(int), 1, file);
|
||||
|
||||
unsigned int nWeights = nn.layers[i].weights.rows * nn.layers[i].weights.cols;
|
||||
fwrite(nn.layers[i].weights.buffer, sizeof(MatrixType), nWeights, file);
|
||||
for(unsigned int i= 0; i<nn.numberOfLayers; i++){
|
||||
dimension = nn.layers[i].weights.rows;
|
||||
fwrite(&dimension, sizeof(int), 1, file);
|
||||
unsigned int nWeights = nn.layers[i].weights.rows * nn.layers[i].weights.cols;
|
||||
|
||||
fwrite(&nn.layers[i].biases.rows, sizeof(nn.layers[i].biases.rows), 1, file);
|
||||
fwrite(&nn.layers[i].biases.cols, sizeof(nn.layers[i].biases.cols), 1, file);
|
||||
|
||||
unsigned int nBiases = nn.layers[i].biases.rows * nn.layers[i].biases.cols;
|
||||
fwrite(nn.layers[i].biases.buffer, sizeof(MatrixType), nBiases, file);
|
||||
fwrite(nn.layers[i].weights.buffer, sizeof(MatrixType), nWeights, file);
|
||||
|
||||
unsigned int nBiases = nn.layers[i].biases.rows * nn.layers[i].biases.cols;
|
||||
fwrite(nn.layers[i].biases.buffer, sizeof(MatrixType), nBiases, file);
|
||||
}
|
||||
dimension = 0;
|
||||
fwrite(&dimension, sizeof(int), 1, file);
|
||||
}
|
||||
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user