Compare commits
15
Commits
main
..
ede0bd8bd8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ede0bd8bd8 | ||
|
|
97df88c0ab | ||
|
|
be07dcffcf | ||
|
|
858673bdca | ||
|
|
619cd95a5c | ||
|
|
6b9711e47d | ||
|
|
653312f8a6 | ||
|
|
2b751ef931 | ||
|
|
0081e8f89e | ||
|
|
d8e759b436 | ||
|
|
3c49920613 | ||
|
|
28944bd871 | ||
|
|
29b2966c63 | ||
|
|
41c164d3b2 | ||
|
|
b4bc2fae8a |
+2
-59
@@ -1,61 +1,4 @@
|
|||||||
# ---> C
|
mnist
|
||||||
# Prerequisites
|
runTests
|
||||||
*.d
|
|
||||||
|
|
||||||
# Object files
|
|
||||||
*.o
|
*.o
|
||||||
*.ko
|
|
||||||
*.obj
|
|
||||||
*.elf
|
|
||||||
|
|
||||||
# Linker output
|
|
||||||
*.ilk
|
|
||||||
*.map
|
|
||||||
*.exp
|
|
||||||
|
|
||||||
# Precompiled Headers
|
|
||||||
*.gch
|
|
||||||
*.pch
|
|
||||||
|
|
||||||
# Libraries
|
|
||||||
*.lib
|
|
||||||
*.la
|
|
||||||
*.lo
|
|
||||||
|
|
||||||
# Shared objects (inc. Windows DLLs)
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.so.*
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Executables
|
|
||||||
*.exe
|
*.exe
|
||||||
*.out
|
|
||||||
*.app
|
|
||||||
*.i*86
|
|
||||||
*.x86_64
|
|
||||||
*.hex
|
|
||||||
Startcode/mnist
|
|
||||||
Startcode/runTests
|
|
||||||
|
|
||||||
# Debug files
|
|
||||||
*.dSYM/
|
|
||||||
*.su
|
|
||||||
*.idb
|
|
||||||
*.pdb
|
|
||||||
|
|
||||||
# Kernel Module Compile Results
|
|
||||||
*.mod*
|
|
||||||
*.cmd
|
|
||||||
.tmp_versions/
|
|
||||||
modules.order
|
|
||||||
Module.symvers
|
|
||||||
Mkfile.old
|
|
||||||
dkms.conf
|
|
||||||
|
|
||||||
# IDE folders
|
|
||||||
.vscode/
|
|
||||||
.idea/
|
|
||||||
|
|
||||||
# macOS
|
|
||||||
.DS_Store
|
|
||||||
|
|||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"makefile.configureOnOpen": false
|
||||||
|
}
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "matrix.h"
|
|
||||||
|
|
||||||
// TODO Matrix-Funktionen implementieren
|
|
||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearMatrix(Matrix *matrix)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -7,16 +7,23 @@
|
|||||||
#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
|
||||||
|
GrayScaleImage readImage()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 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 = fopen("mnist_test.info2","rb");
|
||||||
|
char headOfFile;
|
||||||
|
series = malloc();
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -63,4 +63,3 @@ ifeq ($(OS),Windows_NT)
|
|||||||
else
|
else
|
||||||
rm -f *.o mnist runMatrixTests runNeuralNetworkTests runImageInputTests
|
rm -f *.o mnist runMatrixTests runNeuralNetworkTests runImageInputTests
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
#include "matrix.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// TODO Matrix-Funktionen implementieren
|
||||||
|
/*typedef struct {
|
||||||
|
unsigned int rows; //Zeilen
|
||||||
|
unsigned int cols; //Spalten
|
||||||
|
MatrixType *buffer; //Zeiger auf Speicherbereich Reihen*Spalten
|
||||||
|
} Matrix;*/
|
||||||
|
Matrix createMatrix(unsigned int rows, unsigned int cols) {
|
||||||
|
|
||||||
|
Matrix errorMatrix = {0, 0, NULL};
|
||||||
|
if (rows == 0 || cols == 0) {
|
||||||
|
|
||||||
|
return errorMatrix;
|
||||||
|
}
|
||||||
|
MatrixType *buffer =
|
||||||
|
malloc(rows * cols * sizeof(MatrixType)); // Speicher reservieren, malloc
|
||||||
|
// liefert Zeiger auf Speicher
|
||||||
|
Matrix newMatrix = {rows, cols, buffer}; // neue Matrix nach struct
|
||||||
|
return newMatrix;
|
||||||
|
}
|
||||||
|
void clearMatrix(Matrix *matrix) {
|
||||||
|
matrix->buffer = UNDEFINED_MATRIX_VALUE;
|
||||||
|
matrix->rows = UNDEFINED_MATRIX_VALUE;
|
||||||
|
matrix->cols = UNDEFINED_MATRIX_VALUE;
|
||||||
|
free((*matrix).buffer); // Speicher freigeben
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMatrixAt(const MatrixType value, Matrix matrix,
|
||||||
|
const unsigned int rowIdx, // Kopie der Matrix wird übergeben
|
||||||
|
const unsigned int colIdx) {
|
||||||
|
|
||||||
|
matrix.buffer[rowIdx * matrix.cols + colIdx] =
|
||||||
|
value; // rowIdx * matrix.cols -> Beginn der Zeile colIdx ->Spalte
|
||||||
|
// innerhalb der Zeile
|
||||||
|
}
|
||||||
|
MatrixType getMatrixAt(const Matrix matrix,
|
||||||
|
unsigned int rowIdx, // Kopie der Matrix wird übergeben
|
||||||
|
unsigned int colIdx) {
|
||||||
|
if (rowIdx >= matrix.rows ||
|
||||||
|
colIdx >= matrix.cols) { // Speichergröße nicht überschreiten
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
MatrixType value = matrix.buffer[rowIdx * matrix.cols + colIdx];
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix broadCastCols(const Matrix matrix, const unsigned int rows,
|
||||||
|
const unsigned int cols) {
|
||||||
|
|
||||||
|
Matrix copy = createMatrix(
|
||||||
|
rows, cols); // Matrix 1 Kopie erstellen mit Dimensionen von Matrix2
|
||||||
|
for (int r = 0; r < rows; r++) {
|
||||||
|
|
||||||
|
MatrixType value = getMatrixAt(matrix, r, 0);
|
||||||
|
for (int c = 0; c < cols; c++) {
|
||||||
|
|
||||||
|
setMatrixAt(value, copy, r, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
Matrix broadCastRows(const Matrix matrix, const unsigned int rows,
|
||||||
|
const unsigned int cols) {
|
||||||
|
|
||||||
|
Matrix copy = createMatrix(rows, cols);
|
||||||
|
|
||||||
|
for (int c = 0; c < cols; c++) {
|
||||||
|
MatrixType value = getMatrixAt(matrix, 0, c);
|
||||||
|
|
||||||
|
for (int r = 0; r < rows; r++) {
|
||||||
|
|
||||||
|
setMatrixAt(value, copy, r, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix add(const Matrix matrix1, const Matrix matrix2) {
|
||||||
|
|
||||||
|
// Broadcasting nur bei Vektor und Matrix, Fehlermeldung bei zwei unpassenden
|
||||||
|
// Matrizen
|
||||||
|
|
||||||
|
const unsigned int rows1 = matrix1.rows;
|
||||||
|
const unsigned int rows2 = matrix2.rows;
|
||||||
|
const unsigned int cols1 = matrix1.cols;
|
||||||
|
const unsigned int cols2 = matrix2.cols;
|
||||||
|
|
||||||
|
const int rowsEqual = ((rows1 == rows2) ? 1 : 0);
|
||||||
|
|
||||||
|
const int colsEqual = ((cols1 == cols2) ? 1 : 0);
|
||||||
|
|
||||||
|
if (rowsEqual && colsEqual) // addieren
|
||||||
|
|
||||||
|
{
|
||||||
|
Matrix result = createMatrix(rows1, cols1); // Speicher reservieren
|
||||||
|
|
||||||
|
for (int i = 0; i < (rows1 * cols1); i++) { // addieren
|
||||||
|
|
||||||
|
result.buffer[i] =
|
||||||
|
(matrix1.buffer[i] +
|
||||||
|
matrix2.buffer[i]); // buffer[i] ⇔ *(buffer + i) Adresse =
|
||||||
|
// Startadresse + (i * sizeof(MatrixType))
|
||||||
|
}
|
||||||
|
|
||||||
|
return result; // zurückgeben
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (rowsEqual && !colsEqual) {
|
||||||
|
|
||||||
|
if (cols1 == 1) {
|
||||||
|
|
||||||
|
Matrix result = createMatrix(rows2, cols2);
|
||||||
|
|
||||||
|
Matrix copy1 = broadCastCols(matrix1, rows2, cols2);
|
||||||
|
|
||||||
|
for (int i = 0; i < (rows2 * cols2); i++) { // addieren
|
||||||
|
|
||||||
|
result.buffer[i] =
|
||||||
|
(copy1.buffer[i] +
|
||||||
|
matrix2.buffer[i]); // buffer[i] ⇔ *(buffer + i) Adresse =
|
||||||
|
// Startadresse + (i * sizeof(MatrixType))
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
// add und return
|
||||||
|
|
||||||
|
} else if (cols2 == 1) {
|
||||||
|
|
||||||
|
Matrix result = createMatrix(rows1, cols1);
|
||||||
|
|
||||||
|
Matrix copy2 = broadCastCols(matrix2, rows1, cols1);
|
||||||
|
|
||||||
|
for (int i = 0; i < (rows1 * cols1); i++) { // addieren
|
||||||
|
|
||||||
|
result.buffer[i] =
|
||||||
|
(matrix1.buffer[i] +
|
||||||
|
copy2.buffer[i]); // buffer[i] ⇔ *(buffer + i) Adresse =
|
||||||
|
// Startadresse + (i * sizeof(MatrixType))
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
// add und return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
|
||||||
|
printf("Fehlermeldung"); // vielleicht Fehlermeldung ändern zu
|
||||||
|
// Programmabbruch
|
||||||
|
Matrix error = {0, 0, NULL};
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!rowsEqual && colsEqual) {
|
||||||
|
|
||||||
|
if (rows1 == 1) {
|
||||||
|
|
||||||
|
Matrix result = createMatrix(rows2, cols2);
|
||||||
|
|
||||||
|
Matrix copy1 = broadCastRows(matrix1, rows2, cols2);
|
||||||
|
|
||||||
|
for (int i = 0; i < (rows2 * cols2); i++) { // addieren
|
||||||
|
|
||||||
|
result.buffer[i] =
|
||||||
|
(copy1.buffer[i] +
|
||||||
|
matrix2.buffer[i]); // buffer[i] ⇔ *(buffer + i) Adresse =
|
||||||
|
// Startadresse + (i * sizeof(MatrixType))
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
// add und return
|
||||||
|
|
||||||
|
} else if (rows2 == 1) {
|
||||||
|
|
||||||
|
Matrix result = createMatrix(rows1, cols1);
|
||||||
|
|
||||||
|
Matrix copy2 = broadCastCols(matrix2, rows1, cols1);
|
||||||
|
// add und return
|
||||||
|
|
||||||
|
for (int i = 0; i < (rows1 * cols1); i++) { // addieren
|
||||||
|
|
||||||
|
result.buffer[i] =
|
||||||
|
(matrix1.buffer[i] +
|
||||||
|
copy2.buffer[i]); // buffer[i] ⇔ *(buffer + i) Adresse =
|
||||||
|
// Startadresse + (i * sizeof(MatrixType))
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
|
||||||
|
printf("Fehlermeldung"); // vielleicht Fehlermeldung ändern zu
|
||||||
|
// Programmabbruch
|
||||||
|
Matrix error = {0, 0, NULL};
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
printf(
|
||||||
|
"Fehlermeldung"); // vielleicht Fehlermeldung ändern zu Programmabbruch
|
||||||
|
Matrix error = {0, 0, NULL};
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; }
|
||||||
@@ -6,14 +6,25 @@
|
|||||||
typedef float MatrixType;
|
typedef float MatrixType;
|
||||||
|
|
||||||
// TODO Matrixtyp definieren
|
// TODO Matrixtyp definieren
|
||||||
|
typedef struct {
|
||||||
|
unsigned int rows;
|
||||||
|
unsigned int cols;
|
||||||
|
MatrixType *buffer;
|
||||||
|
|
||||||
|
} 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);
|
||||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx);
|
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx,
|
||||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx);
|
unsigned int colIdx);
|
||||||
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx,
|
||||||
|
unsigned int colIdx);
|
||||||
|
|
||||||
|
Matrix broadCastCols(const Matrix matrix, const unsigned int rows,
|
||||||
|
const unsigned int cols);
|
||||||
|
Matrix broadCastRows(const Matrix matrix, const unsigned int rows,
|
||||||
|
const unsigned int cols);
|
||||||
Matrix add(const Matrix matrix1, const Matrix matrix2);
|
Matrix add(const Matrix matrix1, const Matrix matrix2);
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2);
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
Inhalte: Dynamische Speicherverwaltung, Strukturen, Dateien lesen.
|
||||||
|
|
||||||
|
Ziel: Die Bilder aus mnist_test.info 2 auslesen
|
||||||
|
|
||||||
|
Struktur für einlesen des Strings am Anfang der Datei:
|
||||||
|
int AnzahlBilder
|
||||||
|
int breiteBilder
|
||||||
|
int LaengeBilder
|
||||||
|
|
||||||
|
Struktur für Bilder:
|
||||||
|
unsinged int array Breite * Höhe
|
||||||
|
unsigned int Klasse (Label 0 - 9)
|
||||||
|
|
||||||
|
|
||||||
|
Speicher für Bilder dynamisch allokieren
|
||||||
|
|
||||||
|
GrayScaleImageSeries:
|
||||||
|
datei einlesen
|
||||||
|
header String aus der Datei lesen
|
||||||
|
mit header String den benötigten Speicher freigeben
|
||||||
|
in den Speicher die Datei einschreiben (mit Hilfsfunktion)
|
||||||
|
|
||||||
|
Hilfsfunktion (saveFile)
|
||||||
|
gehe zum Anfang des Strings
|
||||||
|
speicher alles der Reihe nach ein
|
||||||
|
|
||||||
|
clearSeries:
|
||||||
|
pointer der be malloc kommt nehemen
|
||||||
|
free()
|
||||||
Reference in New Issue
Block a user