(try): stochastic gradient decent

This commit is contained in:
Jakob Stornig 2023-09-23 22:05:55 +02:00
parent 86ac3e855c
commit 34a23c6eab
7 changed files with 288 additions and 27 deletions

15
image.c
View file

@ -68,8 +68,8 @@ Image * load_pgm_image(char * image_file_string){
Image** import_images(char* image_file_string, char* label_file_string, int* _number_imported, int count) {
printf("Loading Images\n");
// create file pointer for the image and label data
FILE* image_file = fopen(image_file_string, "r");
FILE* label_file = fopen(label_file_string, "r");
FILE* image_file = fopen(image_file_string, "rb");
FILE* label_file = fopen(label_file_string, "rb");
// check if the file could be opened
if(image_file == NULL || label_file == NULL) {
@ -159,6 +159,17 @@ Image** import_images(char* image_file_string, char* label_file_string, int* _nu
return images;
}
Matrix* create_one_hot_result(Image* image){
if(image->label < 0 || image->label > 9){
printf("create_one_hot_result should only be used on correctly labeled images\n");
exit(1);
}
Matrix* result = matrix_create(10, 1);
result->numbers[image->label][0] = 1;
return result;
}
void img_print (Image* img) {
//print the image