generated from freudenreichan/info2Praktikum-NeuronalesNetz
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e544da140e | ||
|
|
0aa42abd43 | ||
|
|
0f28ee3f02 | ||
|
|
bb96c8f78a | ||
|
|
cfb3848fe2 |
@@ -132,16 +132,3 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
void writeMatrix(Matrix matrix, FILE *file)//Added for neuralNetworkTests
|
|
||||||
{
|
|
||||||
//fprintf(file, "%d%d", matrix.rows, matrix.cols);
|
|
||||||
for(int i = 0; i < matrix.rows; i++)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < matrix.cols; j++)
|
|
||||||
{
|
|
||||||
putw(*(matrix.buffer + (j+i)*sizeof(MatrixType)), file);
|
|
||||||
//fprintf(file, "%f", *(matrix.buffer + (j+i)*sizeof(MatrixType)));
|
|
||||||
printf("%f", *(matrix.buffer + (j+i)*sizeof(MatrixType)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,7 +21,6 @@ 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
-2
@@ -155,7 +155,6 @@ NeuralNetwork loadModel(const char *path)
|
|||||||
|
|
||||||
model.layers[model.numberOfLayers] = layer;
|
model.layers[model.numberOfLayers] = layer;
|
||||||
model.numberOfLayers++;
|
model.numberOfLayers++;
|
||||||
|
|
||||||
inputDimension = outputDimension;
|
inputDimension = outputDimension;
|
||||||
outputDimension = readDimension(file);
|
outputDimension = readDimension(file);
|
||||||
}
|
}
|
||||||
@@ -170,7 +169,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}; // TODO changed this line to fit our functionality
|
||||||
|
|
||||||
if(count > 0 && images != NULL)
|
if(count > 0 && images != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
+25
-13
@@ -4,23 +4,34 @@
|
|||||||
#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)
|
||||||
{
|
{
|
||||||
FILE *testDatei = fopen(path, "w");
|
// TODO
|
||||||
fprintf(testDatei, "__info2_neural_network_file_format__");
|
FILE* file = fopen(path, "wb");
|
||||||
fprintf(testDatei, "%d%d", nn.layers->weights.rows, nn.layers->weights.cols);
|
if(file == NULL) {
|
||||||
// fprintf(testDatei, (char*) nn.numberOfLayers);
|
printf("Failed to open file");
|
||||||
for(int i = 0; i < nn.numberOfLayers; i++)
|
return;
|
||||||
{
|
|
||||||
//fprintf(testDatei, "\n");
|
|
||||||
//putw((nn.layers + sizeof(Layer) * i), testDatei);
|
|
||||||
writeMatrix(nn.layers[i].weights, testDatei);
|
|
||||||
writeMatrix(nn.layers[i].biases, testDatei);
|
|
||||||
}
|
}
|
||||||
fclose(testDatei);
|
printf("\nLayers in pNNF: %d\n", nn.numberOfLayers);
|
||||||
|
const char* header = "__info2_neural_network_file_format__";
|
||||||
|
fwrite(header, sizeof(const char), strlen(header), file);
|
||||||
|
|
||||||
|
for (int i = 0; i < nn.numberOfLayers; i++) {
|
||||||
|
|
||||||
|
fwrite(&(nn.layers[i].weights.cols), sizeof(unsigned int), 1, file);
|
||||||
|
fwrite(&(nn.layers[i].weights.rows), sizeof(unsigned int), 1, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < nn.numberOfLayers; i++) {
|
||||||
|
//write everything to do with weights
|
||||||
|
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.buffer, sizeof(MatrixType), nn.layers[i].biases.rows * nn.layers[i].biases.cols, file);
|
||||||
|
}
|
||||||
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
@@ -37,13 +48,14 @@ void test_loadModelReturnsCorrectNumberOfLayers(void)
|
|||||||
Layer layers[] = {{.weights=weights1, .biases=biases1}, {.weights=weights2, .biases=biases2}};
|
Layer layers[] = {{.weights=weights1, .biases=biases1}, {.weights=weights2, .biases=biases2}};
|
||||||
|
|
||||||
NeuralNetwork expectedNet = {.layers=layers, .numberOfLayers=2};
|
NeuralNetwork expectedNet = {.layers=layers, .numberOfLayers=2};
|
||||||
|
printf("\nexpectedNetLayers: %d", expectedNet.numberOfLayers);
|
||||||
NeuralNetwork netUnderTest;
|
NeuralNetwork netUnderTest;
|
||||||
|
|
||||||
prepareNeuralNetworkFile(path, expectedNet);
|
prepareNeuralNetworkFile(path, expectedNet);
|
||||||
|
|
||||||
netUnderTest = loadModel(path);
|
netUnderTest = loadModel(path);
|
||||||
remove(path);
|
remove(path);
|
||||||
printf("\n%d\n%d\n", netUnderTest.numberOfLayers, expectedNet.numberOfLayers);
|
|
||||||
TEST_ASSERT_EQUAL_INT(expectedNet.numberOfLayers, netUnderTest.numberOfLayers);
|
TEST_ASSERT_EQUAL_INT(expectedNet.numberOfLayers, netUnderTest.numberOfLayers);
|
||||||
clearModel(&netUnderTest);
|
clearModel(&netUnderTest);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user