forked from freudenreichan/info2Praktikum-NeuronalesNetz
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48a4cff14a | ||
|
|
c52b4cb98d | ||
|
|
c47b84a09e | ||
|
|
161bc0c7bf | ||
|
|
34eceac3d3 |
No files matched your search
@@ -7,16 +7,87 @@
|
||||
#define FILE_HEADER_STRING "__info2_image_file_format__"
|
||||
|
||||
// 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
|
||||
GrayScaleImageSeries *readImages(const char *path)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
|
||||
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;
|
||||
}
|
||||
@@ -7,14 +7,6 @@ typedef float MatrixType;
|
||||
|
||||
// TODO Matrixtyp definieren
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int anzahlZeilen;
|
||||
int anzahlSpalten;
|
||||
int speicher[][];
|
||||
|
||||
} Matrix;
|
||||
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
||||
void clearMatrix(Matrix *matrix);
|
||||
|
||||
@@ -8,7 +8,26 @@
|
||||
|
||||
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
|
||||
{
|
||||
// TODO
|
||||
FILE *file = fopen(path, "wb");
|
||||
|
||||
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)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
some_tag
|
||||
Reference in new issue
Block a user