Compare commits
4 Commits
51d02f32c2
...
758dc03ab8
| Author | SHA1 | Date | |
|---|---|---|---|
| 758dc03ab8 | |||
| 93408c1f47 | |||
| ed1191fffd | |||
| 4999631b9e |
24
imageInput.c
24
imageInput.c
@ -16,9 +16,9 @@ unsigned int checkHeaderString (const char *const header);
|
||||
// DONE Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
|
||||
GrayScaleImageSeries *readImages(const char *path)
|
||||
{
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
FILE *readSource = 0;
|
||||
const unsigned int sizeOfStausInfoElementsInBytes = 2;
|
||||
const unsigned int sizeOfStausInfoElementsInBytes = sizeof(unsigned short);
|
||||
const unsigned int amountOfStatusInfoToRead = 1;
|
||||
unsigned int numberOfBytesToRead = 0;
|
||||
unsigned int expectedHeader = 0;
|
||||
@ -29,43 +29,39 @@ GrayScaleImageSeries *readImages(const char *path)
|
||||
|
||||
if (readSource != NULL)
|
||||
{
|
||||
series = calloc(sizeof(unsigned int) + 3* sizeof(headerString), amountOfStatusInfoToRead);
|
||||
series->images = calloc(2*sizeof(unsigned int) + sizeof(headerString), amountOfStatusInfoToRead);
|
||||
series = calloc(3 * sizeof(unsigned int) + 3*sizeof(headerString), amountOfStatusInfoToRead);
|
||||
series->images = calloc(2 * sizeof(unsigned int) + sizeof(headerString), amountOfStatusInfoToRead);
|
||||
|
||||
numberOfBytesToRead = readStatusInfo(readSource, series, headerString, sizeOfStausInfoElementsInBytes, amountOfStatusInfoToRead);
|
||||
|
||||
expectedHeader = checkHeaderString(headerString);
|
||||
|
||||
printf("llu %llu\n", series->count * numberOfBytesToRead * sizeof(GrayScalePixelType));
|
||||
series->images->buffer = calloc((series->count) * numberOfBytesToRead, sizeof(GrayScalePixelType));
|
||||
series->labels = calloc((series->count), sizeof(&(series->labels)));
|
||||
|
||||
if (expectedHeader)
|
||||
{
|
||||
printf("expected Header!\n");
|
||||
// reallocate memory so that each image width can be saved seperately
|
||||
series->images = realloc(series->images, series->count * 2 * sizeof(unsigned int) + sizeof(headerString));
|
||||
series->images = realloc(series->images, series->count * (2 * sizeof(unsigned int) + sizeof(headerString)));
|
||||
|
||||
printf("count: %d", series->count);
|
||||
series->images[2].width = series->images->width;
|
||||
series->images[2].height = series->images->height;
|
||||
/*
|
||||
// for loop was previously running with i < series->count, wich caused programm to crash.
|
||||
for (int i = 0; i < series->count; i++)
|
||||
{
|
||||
series->images[i].width = series->images->width;
|
||||
series->images[i].height = series->images->height;
|
||||
}
|
||||
*/
|
||||
printf("afer for Loop! \n");
|
||||
|
||||
readImagedata(readSource, series, numberOfBytesToRead);
|
||||
}
|
||||
else
|
||||
{
|
||||
series = NULL;
|
||||
}
|
||||
printf("before read Source\n");
|
||||
|
||||
fclose(readSource);
|
||||
}
|
||||
printf("finished reading!\n");
|
||||
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
10
matrix.c
10
matrix.c
@ -47,13 +47,19 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned
|
||||
return;
|
||||
}
|
||||
|
||||
// printf("rowIdx %d\n", rowIdx);
|
||||
// printf("mat.row %d\n", matrix.rows);
|
||||
// printf("colIdx %d\n", colIdx);
|
||||
// printf("mat.cols %d\n", matrix.cols);
|
||||
|
||||
if(rowIdx >= matrix.rows || colIdx >= matrix.cols)
|
||||
{
|
||||
//printf("Ungueltige Indizes beim Setzen!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
|
||||
// printf("%d \n", rowIdx + matrix.cols * colIdx);
|
||||
matrix.buffer[rowIdx + matrix.cols * colIdx] = value;
|
||||
// printf("value %f\n", value);
|
||||
}
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
|
||||
@ -170,14 +170,14 @@ NeuralNetwork loadModel(const char *path)
|
||||
|
||||
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)
|
||||
{
|
||||
matrix = createMatrix(images[0].height * images[0].width, count);
|
||||
|
||||
if(matrix.buffer != NULL)
|
||||
{
|
||||
{
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
for(int j = 0; j < images[i].width * images[i].height; j++)
|
||||
@ -248,7 +248,7 @@ unsigned char *predict(const NeuralNetwork model, const GrayScaleImage images[],
|
||||
Matrix outputBatch = forward(model, inputBatch);
|
||||
|
||||
unsigned char *result = argmax(outputBatch);
|
||||
|
||||
|
||||
clearMatrix(&outputBatch);
|
||||
|
||||
return result;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user