Compare commits
4 Commits
34a471bda6
...
4e238675c8
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e238675c8 | |||
| 284a313751 | |||
| c7c68a0ce0 | |||
| c0760a6646 |
@ -40,8 +40,8 @@ mnistVisualization.o: mnistVisualization.c
|
||||
matrixTests: matrix.o matrixTests.c
|
||||
$(CC) $(CFLAGS) -I$(unityfolder) -o runMatrixTests matrixTests.c matrix.o $(BINARIES)/libunity.a
|
||||
|
||||
neuralNetworkTests: neuralNetwork.o neuralNetworkTests.c
|
||||
$(CC) $(CFLAGS) -I$(unityfolder) -o runNeuralNetworkTests neuralNetworkTests.c neuralNetwork.o $(BINARIES)/libunity.a
|
||||
neuralNetworkTests: neuralNetwork.o neuralNetworkTests.c matrix.o
|
||||
$(CC) $(CFLAGS) -I$(unityfolder) -o runNeuralNetworkTests neuralNetworkTests.c neuralNetwork.o matrix.o $(BINARIES)/libunity.a
|
||||
|
||||
imageInputTests: imageInput.o imageInputTests.c
|
||||
$(CC) $(CFLAGS) -I$(unityfolder) -o runImageInputTests imageInputTests.c imageInput.o $(BINARIES)/libunity.a
|
||||
|
||||
@ -42,7 +42,7 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned
|
||||
{
|
||||
if (matrix.buffer != NULL)
|
||||
{
|
||||
if (rowIdx < matrix.rows || colIdx < matrix.cols)
|
||||
if (rowIdx < matrix.rows && colIdx < matrix.cols)
|
||||
{
|
||||
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
|
||||
}
|
||||
|
||||
@ -5,12 +5,80 @@
|
||||
#include "unity.h"
|
||||
#include "neuralNetwork.h"
|
||||
|
||||
/*
|
||||
################
|
||||
Aufbau Test File
|
||||
################
|
||||
|
||||
|
||||
HEADER
|
||||
|
||||
inputDim
|
||||
outputDim
|
||||
|
||||
-- Layer 1 --
|
||||
weights (outputDim * inputDim * MatrixType)
|
||||
biases (outputDim * MatrixType)
|
||||
|
||||
outputDim
|
||||
|
||||
-- Layer 2 --
|
||||
weights
|
||||
biases
|
||||
|
||||
...
|
||||
...
|
||||
-- Layer n --
|
||||
weights
|
||||
biases
|
||||
|
||||
outputDim = 0 => Ende
|
||||
*/
|
||||
|
||||
|
||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||
{
|
||||
// TODO
|
||||
FILE *file = fopen(path, "wb");
|
||||
if (file)
|
||||
{
|
||||
const char *fileTag = "__info2_neural_network_file_format__";
|
||||
fwrite(fileTag, 1, strlen(fileTag), file);
|
||||
|
||||
//Stopt loadModel, falls keine Layer vorhanden
|
||||
if (nn.numberOfLayers == 0)
|
||||
{
|
||||
int zero = 0;
|
||||
fwrite(&zero, sizeof(int), 1, file);
|
||||
fclose(file);
|
||||
return;
|
||||
}
|
||||
|
||||
// input und output dimension schreiben
|
||||
int inputDim = nn.layers[0].weights.cols;
|
||||
fwrite(&inputDim, sizeof(int), 1, file);
|
||||
|
||||
// für weiter Layer nur outputDimension schreiben
|
||||
for (unsigned int i = 0; i < nn.numberOfLayers; i++)
|
||||
{
|
||||
int outputDim = nn.layers[i].weights.rows;
|
||||
fwrite(&outputDim, sizeof(int), 1, file);
|
||||
|
||||
int weightCount = nn.layers[i].weights.rows * nn.layers[i].weights.cols;
|
||||
fwrite(nn.layers[i].weights.buffer, sizeof(MatrixType), weightCount, file);
|
||||
|
||||
int biasesCount = nn.layers[i].biases.rows * nn.layers[i].biases.cols;
|
||||
fwrite(nn.layers[i].biases.buffer, sizeof(MatrixType), biasesCount, file);
|
||||
}
|
||||
|
||||
// loadModel ließt 0 ein -> Stop
|
||||
int fileEnd = 0;
|
||||
fwrite(&fileEnd, sizeof(int), 1, file);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
|
||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||
{
|
||||
const char *path = "some__nn_test_file.info2";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user