18 Commits
Author SHA1 Message Date
MiraSchütz 732ec57e7f runNeuralNetworkTests weiter 2026-11-16 17:57:54 +01:00
MiraSchütz 47690eaa20 neuralNetworkTests fertig 2026-11-16 17:57:54 +01:00
MiraSchütz 9468b6aea0 neuralNetzwork verändert 2026-11-16 17:57:54 +01:00
MiraSchütz 33d9ac7833 bearbeitet 2026-11-16 17:57:54 +01:00
roesselid103915 ff3ba69099 Merge branch 'inputTests' 2026-11-16 08:51:40 +01:00
roesselid103915 a4cf2c27e5 imageInput korrigiert readimages()2 2026-11-16 08:49:58 +01:00
roesselid103915 4e2bec6081 imageInput korrigiert readimages() 2026-11-16 08:46:30 +01:00
roesselid103915 003d1820d9 imageInput korrigiert2 2026-11-16 08:41:37 +01:00
roesselid103915 d999786d02 imageInput korrigiert durch neue Tests 2026-11-16 08:40:26 +01:00
roesselid103915 9b1e4aab11 Merge branch 'input' 2026-11-16 08:28:01 +01:00
roesselid103915 060b22f50e neue Tests 2026-11-16 08:15:49 +01:00
MiraSchütz ebe3304c54 multiply fertig 2026-11-15 19:46:36 +01:00
MiraSchütz c0f73f9362 fkt multiply verändert 2026-11-15 19:17:09 +01:00
MiraSchütz 205513f901 multiply verändert 2026-11-15 18:30:22 +01:00
MiraSchütz d4e329e098 multiply 2026-11-15 18:26:00 +01:00
MiraSchütz 85369b3bad matrix.c weiter 2026-11-15 17:50:46 +01:00
MiraSchütz ddea2d5d72 matrix.c set und get fertig 2026-11-09 17:55:49 +01:00
MiraSchütz 37341ec9c3 martix.h fertig und matrix.c weiter 2026-11-09 08:26:35 +01:00
8 changed files with 208 additions and 6 deletions

No files matched your search

+5 -4
View File
@@ -53,7 +53,7 @@ GrayScaleImageSeries *readImages(const char *path)
}
GrayScaleImageSeries *pictureSeriesmemory(unsigned short numImagesShort); //static kann nur innerhalb imageInput.c aufgerufen werden
series = pictureSeriesmemory(numImagesShort); //static kann nur innerhalb imageInput.c aufgerufen werden
if (series == NULL) {
fclose(file);
return NULL;
@@ -61,10 +61,11 @@ GrayScaleImageSeries *readImages(const char *path)
if (!PicturesLabelsimport(series, file, widthShort, heightShort)) { //! -> inverter
fclose(file);
clearSeries(series);//Speicher bei Fehler direkt freigeben
return NULL;
}
fclose(file);
return series;
return series; //gibt fertige bildserie zurück
}
@@ -77,7 +78,7 @@ GrayScaleImageSeries *pictureSeriesmemory(unsigned short numImagesShort) {
return NULL;
}
series->count *= (unsigned int)numImagesShort;
series->count = (unsigned int)numImagesShort;
series->images = (GrayScaleImage*)malloc(series->count * sizeof(GrayScaleImage));
series->labels = (unsigned char*)malloc(series->count * sizeof(unsigned char));
@@ -96,7 +97,7 @@ GrayScaleImageSeries *pictureSeriesmemory(unsigned short numImagesShort) {
int PicturesLabelsimport(GrayScaleImageSeries *series, FILE *file, unsigned short widthShort, unsigned short heightShort){
unsigned int pixelsPerImage = (unsigned int)widthShort * heightShort;
for (unsigned int i = 0 < series->count; i++;) {
for (unsigned int i = 0; i < series->count; i++) {
series->images[i].width = (unsigned int)widthShort;
series->images[i].height=(unsigned int)heightShort;
series->images[i].buffer = (GrayScalePixelType *)malloc(pixelsPerImage * sizeof(GrayScalePixelType));
+55
View File
@@ -127,11 +127,66 @@ void tearDown(void) {
// Hier kann Bereinigungsarbeit nach jedem Test durchgeführt werden
}
void test_pictureSeriesmemoryAllocatesCorrectly(void) //testet ob arbeitsspeicher fehlerfrei anfordert
{
unsigned short expectedCount = 3;
GrayScaleImageSeries *series = pictureSeriesmemory(expectedCount);
TEST_ASSERT_NOT_NULL(series);
TEST_ASSERT_EQUAL_UINT32(expectedCount, series->count);
TEST_ASSERT_NOT_NULL(series->images);
TEST_ASSERT_NOT_NULL(series->labels);
clearSeries(series);
}
void test_PicturesLabelsimportReadsDataCorrectly(void)
{
const char *path = "testImport.info2";
const unsigned short count = 2;
const unsigned short width = 4;
const unsigned short height = 4;
const unsigned char expectedLabel = 7;
// Testdatei über die bestehende Hilfsfunktion erzeugen
prepareImageFile(path, width, height, count, expectedLabel);
FILE *file = fopen(path, "rb");
TEST_ASSERT_NOT_NULL(file);
// Header-String + 3x unsigned short (Anzahl, Breite, Höhe) überspringen,
// damit der Dateizeiger exakt vor dem ersten Bild steht
long headerOffset = (long)strlen("__info2_image_file_format__") + 3 * sizeof(unsigned short);
fseek(file, headerOffset, SEEK_SET);
// Speicher mit deiner ersten Hilfsfunktion vorbereiten
GrayScaleImageSeries *series = pictureSeriesmemory(count);
TEST_ASSERT_NOT_NULL(series);
// Deine zweite Hilfsfunktion direkt testen
int result = PicturesLabelsimport(series, file, width, height);
fclose(file);
// Prüfen, ob alles erfolgreich eingelesen wurde
TEST_ASSERT_EQUAL_INT(1, result);
for (unsigned int i = 0; i < count; i++) {
TEST_ASSERT_EQUAL_UINT32(width, series->images[i].width);
TEST_ASSERT_EQUAL_UINT32(height, series->images[i].height);
TEST_ASSERT_NOT_NULL(series->images[i].buffer);
TEST_ASSERT_EQUAL_UINT8(expectedLabel, series->labels[i]);
}
clearSeries(series);
remove(path);
}
int main()
{
UNITY_BEGIN();
printf("\n============================\nImage input tests\n============================\n");
RUN_TEST(test_pictureSeriesmemoryAllocatesCorrectly);
RUN_TEST(test_PicturesLabelsimportReadsDataCorrectly);
RUN_TEST(test_readImagesReturnsCorrectNumberOfImages);
RUN_TEST(test_readImagesReturnsCorrectImageWidth);
RUN_TEST(test_readImagesReturnsCorrectImageHeight);
+109
View File
@@ -6,30 +6,139 @@
Matrix createMatrix(unsigned int rows, unsigned int cols)
{
Matrix matrix;
if (rows == 0 || cols == 0) {
matrix.rows = 0;
matrix.cols = 0;
matrix.buffer = NULL;
return matrix;
}
matrix.buffer = malloc(rows*cols*sizeof(MatrixType));
if (matrix.buffer == NULL) {
matrix.rows = 0;
matrix.cols = 0;
matrix.buffer = NULL;
return matrix;
}
matrix.rows = rows;
matrix.cols = cols;
return matrix;
}
void clearMatrix(Matrix *matrix)
{
free(matrix->buffer);
matrix->buffer = NULL;
matrix->rows = 0;
matrix->cols = 0;
}
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{
if(matrix.rows <= rowIdx || matrix.cols <= colIdx) {
return;
}
unsigned int index = rowIdx * matrix.cols + colIdx;
matrix.buffer[index] = value;
}
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{
if(matrix.rows <= rowIdx || matrix.cols <= colIdx){
return UNDEFINED_MATRIX_VALUE;
}
unsigned int index = rowIdx * matrix.cols + colIdx;
return matrix.buffer[index];
}
Matrix add(const Matrix matrix1, const Matrix matrix2)
{
if(matrix1.rows == matrix2.rows && matrix1.cols == matrix2.cols) {
Matrix resultMatrix = createMatrix(matrix1.rows, matrix1.cols);
if (resultMatrix.buffer == NULL) {
return resultMatrix;
}
for (unsigned int i = 0; i < matrix1.rows*matrix1.cols; i++) {
resultMatrix.buffer[i]=matrix1.buffer[i]+matrix2.buffer[i];
}
return resultMatrix;
}
else if (matrix1.rows == matrix2.rows && (matrix1.cols == 1 || matrix2.cols == 1)) {
Matrix resultMatrix;
if (matrix2.cols == 1) {
resultMatrix = createMatrix(matrix1.rows, matrix1.cols);
if (resultMatrix.buffer == NULL) {
return resultMatrix;
}
for (unsigned int i = 0; i < matrix1.rows*matrix1.cols; i++) {
unsigned int rowIdx = i / matrix1.cols;
resultMatrix.buffer[i] = matrix1.buffer[i] + matrix2.buffer[rowIdx];
}
}
else{
resultMatrix = createMatrix(matrix2.rows, matrix2.cols);
if (resultMatrix.buffer == NULL) {
return resultMatrix;
}
for (unsigned int i = 0; i < matrix2.rows*matrix2.cols; i++) {
unsigned int rowIdx = i / matrix2.cols;
resultMatrix.buffer[i] = matrix2.buffer[i] + matrix1.buffer[rowIdx];
}
}
return resultMatrix;
}
else {
Matrix result;
result.rows = 0;
result.cols = 0;
result.buffer = NULL;
return result;
}
}
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
{
if(matrix1.cols !=matrix2.rows){
Matrix result;
result.rows = 0;
result.cols = 0;
result.buffer = NULL;
return result;
}
Matrix resultMatrix = createMatrix(matrix1.rows, matrix2.cols);
if (resultMatrix.buffer == NULL) {
return resultMatrix;
}
for (unsigned int i = 0; i < matrix1.rows; i++) {
for (unsigned int j = 0; j < matrix2.cols; j++) {
MatrixType sum = 0;
for (unsigned int k = 0; k < matrix1.cols; k++) {
sum += getMatrixAt(matrix1, i, k) * getMatrixAt(matrix2, k, j);
}
setMatrixAt(sum, resultMatrix, i, j);
}
}
return resultMatrix;
}
+6
View File
@@ -5,6 +5,12 @@
typedef float MatrixType;
typedef struct Matrix{
unsigned int rows;
unsigned int cols;
MatrixType* buffer;
} Matrix;
// TODO Matrixtyp definieren
+1
View File
@@ -123,6 +123,7 @@ void test_multiplyFailsOnWrongInputDimensions(void)
Matrix matrix1 = {.rows=2, .cols=3, .buffer=buffer1};
Matrix matrix2 = {.rows=2, .cols=3, .buffer=buffer2};
Matrix result = multiply(matrix1, matrix2);
TEST_ASSERT_NULL(result.buffer);
+1 -1
View File
@@ -170,7 +170,7 @@ NeuralNetwork loadModel(const char *path)
static Matrix imageBatchToMatrixOfImageVectors(const GrayScaleImage images[], unsigned int count)
{
Matrix matrix = {NULL, 0, 0};
Matrix matrix = {0, 0, NULL};
if(count > 0 && images != NULL)
{
+31 -1
View File
@@ -8,7 +8,37 @@
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__";
fwrite(fileTag, sizeof(char), strlen(fileTag), file);
if(nn.numberOfLayers > 0){
int dimension;
dimension = nn.layers[0].weights.cols;
fwrite(&dimension, sizeof(int), 1, file);
for(unsigned int i= 0; i<nn.numberOfLayers; i++){
dimension = nn.layers[i].weights.rows;
fwrite(&dimension, sizeof(int), 1, file);
unsigned int nWeights = nn.layers[i].weights.rows * nn.layers[i].weights.cols;
fwrite(nn.layers[i].weights.buffer, sizeof(MatrixType), nWeights, file);
unsigned int nBiases = nn.layers[i].biases.rows * nn.layers[i].biases.cols;
fwrite(nn.layers[i].biases.buffer, sizeof(MatrixType), nBiases, file);
}
dimension = 0;
fwrite(&dimension, sizeof(int), 1, file);
}
fclose(file);
}
}
void test_loadModelReturnsCorrectNumberOfLayers(void)
BIN
View File
Binary file not shown.