forked from freudenreichan/info2Praktikum-NeuronalesNetz
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2761ee453a | ||
|
|
355fd11e2a |
No files matched your search
@@ -7,87 +7,16 @@
|
|||||||
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
||||||
|
|
||||||
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
|
||||||
int readHeader(FILE *file)
|
|
||||||
{
|
|
||||||
char fileHeader[32];
|
|
||||||
|
|
||||||
fread(fileHeader, sizeof(char), strlen(FILE_HEADER_STRING), file);
|
|
||||||
|
|
||||||
if(strncmp(FILE_HEADER_STRING, fileHeader, strlen(FILE_HEADER_STRING))){
|
|
||||||
return -1;
|
|
||||||
} else{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned short readUnShortOfFile(FILE *file){
|
|
||||||
unsigned short number = 0;
|
|
||||||
|
|
||||||
if(fread(&number, sizeof(unsigned short), 1, file) != 1){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return number;
|
|
||||||
}
|
|
||||||
|
|
||||||
int readOneImage(GrayScaleImageSeries *series, FILE *file, unsigned short width, unsigned short height, unsigned short i){
|
|
||||||
|
|
||||||
series->images[i].buffer = malloc(width * height * sizeof(GrayScalePixelType));
|
|
||||||
fread(series->images[i].buffer, sizeof(GrayScalePixelType), width * height, file);
|
|
||||||
fread(&series->labels[i], sizeof(unsigned char), 1, file);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||||
GrayScaleImageSeries *readImages(const char *path)
|
GrayScaleImageSeries *readImages(const char *path)
|
||||||
{
|
{
|
||||||
GrayScaleImageSeries *series = NULL;
|
GrayScaleImageSeries *series = NULL;
|
||||||
FILE *file;
|
|
||||||
unsigned short width, height;
|
|
||||||
|
|
||||||
file = fopen(path, "rb");
|
|
||||||
|
|
||||||
if(file == NULL || readHeader(file) == -1) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
series = malloc(sizeof(GrayScaleImageSeries));
|
|
||||||
|
|
||||||
series->count = readUnShortOfFile(file);
|
|
||||||
width = readUnShortOfFile(file);
|
|
||||||
height = readUnShortOfFile(file);
|
|
||||||
|
|
||||||
if(series->count == -1 || width == -1 || height == -1){
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
series->images = malloc(series->count * sizeof(GrayScaleImage));
|
|
||||||
series->labels = malloc(series->count * sizeof(unsigned char));
|
|
||||||
|
|
||||||
for(int i = 0; i < series->count; i++){
|
|
||||||
series->images[i].width = width;
|
|
||||||
series->images[i].height = height;
|
|
||||||
readOneImage(series, file, width, height, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return series;
|
return series;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
|
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
|
||||||
void clearSeries(GrayScaleImageSeries *series)
|
void clearSeries(GrayScaleImageSeries *series)
|
||||||
{
|
{
|
||||||
if(series == NULL){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < series->count; i++){
|
|
||||||
free(series->images[i].buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(series->images);
|
|
||||||
free(series->labels);
|
|
||||||
free(series);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
@@ -6,11 +6,23 @@
|
|||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||||
{
|
{
|
||||||
|
Matrix matrix;
|
||||||
|
|
||||||
|
matrix.anzahlSpalten = cols;
|
||||||
|
matrix.anzahlZeilen = rows;
|
||||||
|
|
||||||
|
matrix.buffer = mallloc(cols*rows*(sizeof(Matrix)));
|
||||||
|
|
||||||
|
return matrix;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearMatrix(Matrix *matrix)
|
void clearMatrix(Matrix *matrix)
|
||||||
{
|
{
|
||||||
|
free(matrix->buffer);
|
||||||
|
|
||||||
|
matrix->buffer = NULL;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,22 @@
|
|||||||
#define MATRIX_H
|
#define MATRIX_H
|
||||||
|
|
||||||
#define UNDEFINED_MATRIX_VALUE 0
|
#define UNDEFINED_MATRIX_VALUE 0
|
||||||
|
#define M 100
|
||||||
|
|
||||||
typedef float MatrixType;
|
typedef float MatrixType;
|
||||||
|
|
||||||
|
|
||||||
// TODO Matrixtyp definieren
|
// TODO Matrixtyp definieren
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
MatrixType* buffer;
|
||||||
|
int anzahlZeilen;
|
||||||
|
int anzahlSpalten;
|
||||||
|
|
||||||
|
|
||||||
|
} Matrix;
|
||||||
|
|
||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
||||||
void clearMatrix(Matrix *matrix);
|
void clearMatrix(Matrix *matrix);
|
||||||
|
|||||||
@@ -8,26 +8,7 @@
|
|||||||
|
|
||||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||||
{
|
{
|
||||||
FILE *file = fopen(path, "wb");
|
// TODO
|
||||||
|
|
||||||
if(file != NULL)
|
|
||||||
{
|
|
||||||
const char *fileTag = "__info2_neural_network_file_format__";
|
|
||||||
|
|
||||||
if(zeroBuffer != NULL)
|
|
||||||
{
|
|
||||||
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
|
|
||||||
|
|
||||||
for(int i = 0; i < nn->numberOfLayers; i++)
|
|
||||||
{
|
|
||||||
fwrite(nn->layers[i].weights, sizeof(nn->layers[i].weights), 1, file);
|
|
||||||
fwrite(nn->layers[i].biases, sizeof(nn->layers[i].biases), 1, file);
|
|
||||||
fwrite(nn->layers[i].activation, sizeof(nn->layers[i].activation), 1, file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
void test_loadModelReturnsCorrectNumberOfLayers(void)
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
some_tag
|
|
||||||
Reference in new issue
Block a user