forked from freudenreichan/info2Praktikum-NeuronalesNetz
sync
This commit is contained in:
parent
ff21ecab21
commit
44f0bfc16d
4
matrix.c
4
matrix.c
@ -6,13 +6,13 @@
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
{
|
||||
Matrix m = {0, 0, NULL};
|
||||
Matrix m = {NULL, 0, 0};
|
||||
|
||||
if (rows > 0 && cols > 0)
|
||||
{
|
||||
m.buffer = malloc(rows * cols * sizeof(int));
|
||||
m.rows = rows;
|
||||
m.cols = cols;
|
||||
m.buffer = malloc(rows * cols * sizeof(int));
|
||||
}
|
||||
|
||||
return m;
|
||||
|
||||
2
matrix.h
2
matrix.h
@ -9,9 +9,9 @@ typedef float MatrixType;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
MatrixType *buffer; // Zeiger auf die Matrixdaten
|
||||
unsigned int rows; // Anzahl der Zeilen
|
||||
unsigned int cols; // Anzahl der Spalten
|
||||
MatrixType *buffer; // Zeiger auf die Matrixdaten
|
||||
} Matrix;
|
||||
|
||||
|
||||
|
||||
@ -8,7 +8,43 @@
|
||||
|
||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||
{
|
||||
// TODO
|
||||
FILE *file = fopen(path, "wb");
|
||||
if (file == NULL) {
|
||||
perror("Fehler beim Erstellen der Testdatei");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Dateikopf speichern
|
||||
const char *fileTag = "info2_neural_network_file_format";
|
||||
fwrite(fileTag, sizeof(char), strlen(fileTag), file);
|
||||
|
||||
// Dimensionen der Eingabe und Ausgabe für den ersten Layer speichern
|
||||
unsigned int inputDimension = nn.layers[0].weights.rows; // Eingabedimension ist die Anzahl der Eingabeneuronen im ersten Layer
|
||||
unsigned int outputDimension = nn.layers[0].weights.cols; // Ausgabedimension ist die Anzahl der Ausgabeneuronen im ersten Layer
|
||||
fwrite(&inputDimension, sizeof(unsigned int), 1, file);
|
||||
fwrite(&outputDimension, sizeof(unsigned int), 1, file);
|
||||
|
||||
// Alle Layer speichern
|
||||
for (unsigned int i = 0; i < nn.numberOfLayers; i++) {
|
||||
// Layer-Dimensionen speichern
|
||||
inputDimension = nn.layers[i].weights.rows;
|
||||
outputDimension = nn.layers[i].weights.cols;
|
||||
|
||||
fwrite(&inputDimension, sizeof(unsigned int), 1, file);
|
||||
fwrite(&outputDimension, sizeof(unsigned int), 1, file);
|
||||
|
||||
// Gewichte speichern
|
||||
fwrite(&nn.layers[i].weights.rows, sizeof(unsigned int), 1, file);
|
||||
fwrite(&nn.layers[i].weights.cols, sizeof(unsigned int), 1, file);
|
||||
fwrite(nn.layers[i].weights.buffer, sizeof(MatrixType), nn.layers[i].weights.rows * nn.layers[i].weights.cols, file);
|
||||
|
||||
// Biases speichern
|
||||
fwrite(&nn.layers[i].biases.rows, sizeof(unsigned int), 1, file);
|
||||
fwrite(&nn.layers[i].biases.cols, sizeof(unsigned int), 1, file);
|
||||
fwrite(nn.layers[i].biases.buffer, sizeof(MatrixType), nn.layers[i].biases.rows * nn.layers[i].biases.cols, file);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user