generated from freudenreichan/info2Praktikum-NeuronalesNetz
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06782431a4 |
No files matched your search
@@ -131,4 +131,14 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
void writeMatrix(Matrix matrix, FILE *file)//Added for neuralNetworkTests
|
||||||
|
{
|
||||||
|
for(int i = 0; i < matrix.rows; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < matrix.cols; j++)
|
||||||
|
{
|
||||||
|
fprintf(file, (char*)(matrix.buffer + (j+i)*sizeof(MatrixType)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned
|
|||||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx);
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx);
|
||||||
Matrix add(const Matrix matrix1, const Matrix matrix2);
|
Matrix add(const Matrix matrix1, const Matrix matrix2);
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2);
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2);
|
||||||
|
void writeMatrix(Matrix matrix, FILE *file);//Added for neuralNetworkTests
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+1
-1
@@ -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 = {0, 0, NULL}; // TODO changed this line to fit our functionality
|
Matrix matrix = {NULL, 0, 0};
|
||||||
|
|
||||||
if(count > 0 && images != NULL)
|
if(count > 0 && images != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
+9
-22
@@ -4,33 +4,20 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "neuralNetwork.h"
|
#include "neuralNetwork.h"
|
||||||
|
#include "matrix.h"
|
||||||
|
|
||||||
|
|
||||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||||
{
|
{
|
||||||
// TODO
|
FILE *testDatei = fopen(path, "w");
|
||||||
FILE* file = fopen(path, "wb");
|
fprintf(testDatei, "__info2_neural_network_file_format__");
|
||||||
if(file == NULL) {
|
for(int i = 0; i < nn.numberOfLayers; i++)
|
||||||
printf("Failed to open file");
|
{
|
||||||
return;
|
fprintf(testDatei, "\n");
|
||||||
|
writeMatrix(nn.layers[i].weights, testDatei);
|
||||||
|
writeMatrix(nn.layers[i].biases, testDatei);
|
||||||
}
|
}
|
||||||
|
fclose(testDatei);
|
||||||
const char* header = "__info2_neural_network_file_format__";
|
|
||||||
fwrite(header, sizeof(const char), strlen(header), file);
|
|
||||||
fwrite(&(nn.numberOfLayers), sizeof(unsigned int), 1, file);
|
|
||||||
fwrite(&(nn.numberOfLayers), sizeof(unsigned int), 1, file);
|
|
||||||
for(int i = 0; i < nn.numberOfLayers; i++) {
|
|
||||||
//write everything to do with weights
|
|
||||||
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);
|
|
||||||
|
|
||||||
//write everything to do with biases
|
|
||||||
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)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
|
|||||||
Reference in new issue
Block a user