generated from freudenreichan/info2Praktikum-NeuronalesNetz
Änderung an neuralesNetwork.c vorgenommen, weil es die Funktion aus
matrix.c falsch benutzt hat
This commit is contained in:
1 parent
8c8637bc48
commit
3af1970eb7
2 files changed
+9
-9
No files matched your search
@@ -67,14 +67,14 @@ static unsigned int readDimension(FILE *file)
|
|||||||
|
|
||||||
if(fread(&dimension, sizeof(int), 1, file) != 1)
|
if(fread(&dimension, sizeof(int), 1, file) != 1)
|
||||||
dimension = 0;
|
dimension = 0;
|
||||||
|
|
||||||
return dimension;
|
return dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Matrix readMatrix(FILE *file, unsigned int rows, unsigned int cols)
|
static Matrix readMatrix(FILE *file, unsigned int rows, unsigned int cols)
|
||||||
{
|
{
|
||||||
Matrix matrix = createMatrix(rows, cols);
|
Matrix matrix = createMatrix(rows, cols);
|
||||||
|
|
||||||
if(matrix.buffer != NULL)
|
if(matrix.buffer != NULL)
|
||||||
{
|
{
|
||||||
if(fread(matrix.buffer, sizeof(MatrixType), rows*cols, file) != rows*cols)
|
if(fread(matrix.buffer, sizeof(MatrixType), rows*cols, file) != rows*cols)
|
||||||
@@ -128,7 +128,7 @@ NeuralNetwork loadModel(const char *path)
|
|||||||
{
|
{
|
||||||
if(checkFileHeader(file))
|
if(checkFileHeader(file))
|
||||||
{
|
{
|
||||||
unsigned int inputDimension = readDimension(file);
|
unsigned int inputDimension = readDimension(file);
|
||||||
unsigned int outputDimension = readDimension(file);
|
unsigned int outputDimension = readDimension(file);
|
||||||
|
|
||||||
while(inputDimension > 0 && outputDimension > 0)
|
while(inputDimension > 0 && outputDimension > 0)
|
||||||
@@ -142,7 +142,7 @@ NeuralNetwork loadModel(const char *path)
|
|||||||
clearModel(&model);
|
clearModel(&model);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
layerBuffer = (Layer *)realloc(model.layers, (model.numberOfLayers + 1) * sizeof(Layer));
|
layerBuffer = (Layer *)realloc(model.layers, (model.numberOfLayers + 1) * sizeof(Layer));
|
||||||
|
|
||||||
if(layerBuffer != NULL)
|
if(layerBuffer != NULL)
|
||||||
@@ -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 = {NULL, 0, 0};
|
Matrix matrix = {0, 0, NULL};
|
||||||
|
|
||||||
if(count > 0 && images != NULL)
|
if(count > 0 && images != NULL)
|
||||||
{
|
{
|
||||||
@@ -201,7 +201,7 @@ static Matrix forward(const NeuralNetwork model, Matrix inputBatch)
|
|||||||
{
|
{
|
||||||
Matrix biasResult;
|
Matrix biasResult;
|
||||||
Matrix weightResult;
|
Matrix weightResult;
|
||||||
|
|
||||||
weightResult = multiply(model.layers[i].weights, result);
|
weightResult = multiply(model.layers[i].weights, result);
|
||||||
clearMatrix(&result);
|
clearMatrix(&result);
|
||||||
biasResult = add(model.layers[i].biases, weightResult);
|
biasResult = add(model.layers[i].biases, weightResult);
|
||||||
@@ -248,9 +248,9 @@ unsigned char *predict(const NeuralNetwork model, const GrayScaleImage images[],
|
|||||||
Matrix outputBatch = forward(model, inputBatch);
|
Matrix outputBatch = forward(model, inputBatch);
|
||||||
|
|
||||||
unsigned char *result = argmax(outputBatch);
|
unsigned char *result = argmax(outputBatch);
|
||||||
|
|
||||||
clearMatrix(&outputBatch);
|
clearMatrix(&outputBatch);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,4 +265,4 @@ void clearModel(NeuralNetwork *model)
|
|||||||
model->layers = NULL;
|
model->layers = NULL;
|
||||||
model->numberOfLayers = 0;
|
model->numberOfLayers = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Executable
BIN
Binary file not shown.
Reference in new issue
Block a user