aggiornato classificatore singolo per mnist
This commit is contained in:
@@ -1,3 +1,16 @@
|
||||
/*
|
||||
Il file MNIST in formato IDX ha questa struttura:
|
||||
Byte 0-3: Numero magico (4 byte).
|
||||
Byte 4-7: Numero di immagini (4 byte).
|
||||
Byte 8-11: Numero di righe per immagine (4 byte).
|
||||
Byte 12-15: Numero di colonne per immagine (4 byte).
|
||||
Byte 16 in poi: Dati delle immagini (ogni immagine è composta da 28x28 = 784 byte).
|
||||
|
||||
Le immagini sono 28x28 pixel.
|
||||
I dati sono byte non firmati (valori da 0 a 255).
|
||||
Il file contiene 60.000 immagini (per il training set),
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -29,7 +42,6 @@ Dataset *get_dataset(char *path_mnist, char *path_categoria)
|
||||
Dataset *set = (Dataset *)malloc(sizeof(Dataset));
|
||||
FILE *file;
|
||||
FILE *categorie;
|
||||
Istanza istanza;
|
||||
Istanza *istanze = (Istanza *)malloc(sizeof(Istanza));
|
||||
|
||||
file = fopen(path_mnist, "rb");
|
||||
@@ -46,16 +58,15 @@ Dataset *get_dataset(char *path_mnist, char *path_categoria)
|
||||
|
||||
int numero_righe = 0;
|
||||
|
||||
//printf("Scorro il while %d\n", fread(istanze[numero_righe].categoria, sizeof(byte), 2, categorie));
|
||||
|
||||
// Fino a quando questo fread restituisce 1 significa che il file contiene ancora roba
|
||||
while (fread(istanze[numero_righe].immagine, sizeof(byte), N_PIXEL, file) == N_PIXEL)
|
||||
{
|
||||
if(fread(&istanze[numero_righe].categoria, sizeof(byte), 1, categorie) == 1) {
|
||||
numero_righe++;
|
||||
istanze = (Istanza *)realloc(istanze, sizeof(Istanza) * (numero_righe + 1));
|
||||
//Leggo male il file, cambiare in base alle dichiarazioni sopra
|
||||
if(fread(istanze[numero_righe].immagine, sizeof(byte), 16, file) == 16)
|
||||
while (fread(istanze[numero_righe].immagine, sizeof(byte), N_PIXEL, file) == N_PIXEL)
|
||||
{
|
||||
if(fread(&istanze[numero_righe].categoria, sizeof(byte), 1, categorie) == 1) {
|
||||
numero_righe++;
|
||||
istanze = (Istanza *)realloc(istanze, sizeof(Istanza) * (numero_righe + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dataset set;
|
||||
(*set).size = numero_righe;
|
||||
|
||||
Reference in New Issue
Block a user