Compare commits
20
Commits
dd2a621f11
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
255cd1a36b | ||
|
|
868007ad49 | ||
|
|
4e37ac0a5e | ||
|
|
e1c80bf60c | ||
|
|
51a71ba61f | ||
|
|
4cb06d2951 | ||
|
|
7698e94944 | ||
|
|
0a909936ed | ||
|
|
d59ffa6888 | ||
|
|
6a5bc9796b | ||
|
|
ecc46da743 | ||
|
|
c19508d6b2 | ||
|
|
f149efb86a | ||
|
|
758dc03ab8 | ||
|
|
93408c1f47 | ||
|
|
ed1191fffd | ||
|
|
4999631b9e | ||
|
|
51d02f32c2 | ||
|
|
a23369ea4c | ||
|
|
e2375c4844 |
+38
-34
@@ -16,9 +16,9 @@ unsigned int checkHeaderString (const char *const header);
|
|||||||
// DONE Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
// DONE 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 *readSource = 0;
|
FILE *readSource = 0;
|
||||||
const unsigned int sizeOfStausInfoElementsInBytes = 2;
|
const unsigned int sizeOfStausInfoElementsInBytes = sizeof(unsigned short);
|
||||||
const unsigned int amountOfStatusInfoToRead = 1;
|
const unsigned int amountOfStatusInfoToRead = 1;
|
||||||
unsigned int numberOfBytesToRead = 0;
|
unsigned int numberOfBytesToRead = 0;
|
||||||
unsigned int expectedHeader = 0;
|
unsigned int expectedHeader = 0;
|
||||||
@@ -29,20 +29,21 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
|
|
||||||
if (readSource != NULL)
|
if (readSource != NULL)
|
||||||
{
|
{
|
||||||
series = calloc(sizeof(unsigned int) + 3* sizeof(headerString), amountOfStatusInfoToRead);
|
series = calloc (amountOfStatusInfoToRead, sizeof(GrayScaleImageSeries));
|
||||||
series->images = calloc(2*sizeof(unsigned int) + sizeof(headerString), amountOfStatusInfoToRead);
|
series->images = calloc (amountOfStatusInfoToRead, sizeof(GrayScaleImage));
|
||||||
|
|
||||||
numberOfBytesToRead = readStatusInfo(readSource, series, headerString, sizeOfStausInfoElementsInBytes, amountOfStatusInfoToRead);
|
numberOfBytesToRead = readStatusInfo (readSource, series, headerString, sizeOfStausInfoElementsInBytes, amountOfStatusInfoToRead);
|
||||||
|
expectedHeader = checkHeaderString (headerString);
|
||||||
|
|
||||||
expectedHeader = checkHeaderString(headerString);
|
series->images = realloc (series->images, series->count * sizeof(GrayScaleImage));
|
||||||
|
series->labels = calloc (series->count, sizeof(&(series->labels)));
|
||||||
series->images->buffer = calloc((series->count) * numberOfBytesToRead, sizeof(GrayScalePixelType));
|
|
||||||
series->labels = calloc((series->count), sizeof(&(series->labels)));
|
|
||||||
|
|
||||||
if (expectedHeader)
|
if (expectedHeader)
|
||||||
{
|
{
|
||||||
// reallocate memory so that each image width can be saved seperately
|
for (int i = 0; i < series->count; i++)
|
||||||
series->images = realloc(series->images, series->count * 2 * sizeof(unsigned int) + sizeof(headerString));
|
{
|
||||||
|
series->images[i].buffer = calloc(numberOfBytesToRead, sizeof(unsigned char));
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < series->count; i++)
|
for (int i = 0; i < series->count; i++)
|
||||||
{
|
{
|
||||||
@@ -54,12 +55,14 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
series = NULL;
|
fclose(readSource);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(readSource);
|
fclose(readSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return series;
|
return series;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,35 +71,36 @@ GrayScaleImageSeries *readImages(const char *path)
|
|||||||
void clearSeries(GrayScaleImageSeries * series)
|
void clearSeries(GrayScaleImageSeries * series)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
|
||||||
|
|
||||||
// Write NULL into all memory spaces
|
for (i = 0; i < series->count; i++)
|
||||||
for (i = 0; i < ((series->count) * (series->images->width) * (series->images->height) / 4); i++)
|
|
||||||
{
|
{
|
||||||
*(series->images->buffer + i * 4 * (series->images->width) * (series->images->height)) = '\0';
|
if (i >= 0)
|
||||||
|
{
|
||||||
|
for (j = 0; j < series->images[i].width * series->images[i].height; j++)
|
||||||
|
{
|
||||||
|
series->images[i].buffer[j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
series->labels[i] = 0;
|
||||||
|
series->images[i].width = 0;
|
||||||
|
series->images[i].height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < (series->count); i++)
|
for (i = 0; i < series->count; i++)
|
||||||
{
|
{
|
||||||
*(series->labels + i) = '\0';
|
free(series->images[i].buffer);
|
||||||
|
series->images[i].buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
series->count = 0;
|
|
||||||
series->images->width = 0;
|
|
||||||
series->images->height = 0;
|
|
||||||
|
|
||||||
// Closse all allocated memory
|
|
||||||
// AND write NULL into every pointer
|
|
||||||
// so they can't be accessed
|
|
||||||
free(series->images->buffer);
|
|
||||||
series->images->buffer = NULL;
|
|
||||||
free(series->labels);
|
free(series->labels);
|
||||||
series->labels = NULL;
|
series->labels = NULL;
|
||||||
free(series->images);
|
free(series->images);
|
||||||
series->images = NULL;
|
series->images = NULL;
|
||||||
free(series);
|
free(series);
|
||||||
series = NULL;
|
series = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -119,15 +123,15 @@ unsigned int readStatusInfo(FILE *const source, GrayScaleImageSeries *const seri
|
|||||||
|
|
||||||
|
|
||||||
// reads the imagebytes and the label of all images
|
// reads the imagebytes and the label of all images
|
||||||
void readImagedata(FILE *const source, GrayScaleImageSeries *const series, int const amountOfBytes)
|
void readImagedata(FILE *const source, GrayScaleImageSeries *const series, int const amountToRead)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < series->count ; i++)
|
for (i = 0; i < series->count ; i++)
|
||||||
{
|
{
|
||||||
fread(&(series->images->buffer[i]), sizeof(*series->images->buffer), amountOfBytes, source);
|
fread(&series->images[i].buffer[0], sizeof(*series->images->buffer), amountToRead, source);
|
||||||
fread(&(series->labels[i]), sizeof(*series->images->buffer), sizeof(*series->labels), source);
|
fread(&series->labels[i], sizeof(*series->images->buffer), sizeof(*series->labels), source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ unityfolder = ./unity
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
# Initiales Programm bauen (zum ausprobieren)
|
# Initiales Programm bauen (zum ausprobieren)
|
||||||
# --------------------------
|
# --------------------------
|
||||||
mnist_initial: $(BINARIES)/libmnist_complete.a
|
#mnist_initial: $(BINARIES)/libmnist_complete.a
|
||||||
$(CC) -o mnist $(BINARIES)/libmnist_complete.a $(BINARIES)/libraylib.a ${LDFLAGS}
|
# $(CC) -o mnist $(BINARIES)/libmnist_complete.a $(BINARIES)/libraylib.a ${LDFLAGS}
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Selbst implementiertes Programm bauen
|
# Selbst implementiertes Programm bauen
|
||||||
|
|||||||
@@ -39,21 +39,23 @@ void clearMatrix(Matrix *matrix)
|
|||||||
matrix->cols = 0;
|
matrix->cols = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMatrixAt(MatrixType value, Matrix *matrix, unsigned int rowIdx, unsigned int colIdx)
|
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||||
{
|
{
|
||||||
|
// printf("hier0\n");
|
||||||
if(matrix.buffer == NULL)
|
if(matrix.buffer == NULL)
|
||||||
{
|
{
|
||||||
//printf("Fehler beim Setzen! Matrix nicht initialisiert");
|
// printf("Fehler beim Setzen! Matrix nicht initialisiert");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rowIdx >= matrix.rows || colIdx >= matrix.cols)
|
if(rowIdx >= matrix.rows || colIdx >= matrix.cols)
|
||||||
{
|
{
|
||||||
//printf("Ungueltige Indizes beim Setzen!\n");
|
// printf("Ungueltige Indizes beim Setzen!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// printf("hier1\n");
|
||||||
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
|
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
|
||||||
|
// printf("hier2\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||||
|
|||||||
+2
-1
@@ -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 = {/*NULL,*/ 0, 0, NULL};
|
||||||
|
|
||||||
if(count > 0 && images != NULL)
|
if(count > 0 && images != NULL)
|
||||||
{
|
{
|
||||||
@@ -182,6 +182,7 @@ static Matrix imageBatchToMatrixOfImageVectors(const GrayScaleImage images[], un
|
|||||||
{
|
{
|
||||||
for(int j = 0; j < images[i].width * images[i].height; j++)
|
for(int j = 0; j < images[i].width * images[i].height; j++)
|
||||||
{
|
{
|
||||||
|
// printf("i %d, j %d \n", i,j);
|
||||||
setMatrixAt((MatrixType)images[i].buffer[j], matrix, j, i);
|
setMatrixAt((MatrixType)images[i].buffer[j], matrix, j, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user