integrazione mnist
This commit is contained in:
10
cifar-10/batches.meta.txt
Normal file
10
cifar-10/batches.meta.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
airplane
|
||||
automobile
|
||||
bird
|
||||
cat
|
||||
deer
|
||||
dog
|
||||
frog
|
||||
horse
|
||||
ship
|
||||
truck
|
||||
76
cifar-10/cifar10_manager.h
Normal file
76
cifar-10/cifar10_manager.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define N_PIXEL 3072 // 1024 pixel * 3 (R, G, B)
|
||||
|
||||
// Siccome il char è un byte che rappresenta il valore tra 0 e 255. Per evitare confusioni definisco il tipo "byte" come in Java
|
||||
typedef unsigned char byte;
|
||||
|
||||
// Singola istanza del dataset.
|
||||
typedef struct
|
||||
{
|
||||
byte categoria;
|
||||
byte immagine[N_PIXEL];
|
||||
} Istanza;
|
||||
|
||||
// Questo tipo fornisce il vettore delle istanze e il size (dimensione) del vettore
|
||||
typedef struct
|
||||
{
|
||||
int size;
|
||||
Istanza *istanze;
|
||||
} Dataset;
|
||||
|
||||
Dataset *get_dataset(char *);
|
||||
|
||||
// Questo metodo legge il file in questione e restituisce un puntatore a Dataset se il file esiste, altrimenti NULL
|
||||
// Ritorna un puntatore perchè in questo caso posso gestire il ritorno NULL.
|
||||
Dataset *get_dataset(char *path)
|
||||
{
|
||||
Dataset *set = (Dataset *)malloc(sizeof(Dataset));
|
||||
FILE *file;
|
||||
Istanza istanza;
|
||||
Istanza *istanze = (Istanza *)malloc(sizeof(Istanza));
|
||||
|
||||
file = fopen(path, "rb");
|
||||
if (file == NULL)
|
||||
return NULL;
|
||||
|
||||
int numero_righe = 0;
|
||||
|
||||
// Fino a quando questo fread restituisce 1 significa che il file contiene ancora roba
|
||||
while (fread(&istanze[numero_righe].categoria, sizeof(byte), 1, file) == 1)
|
||||
{
|
||||
if (fread(istanze[numero_righe].immagine, sizeof(byte), N_PIXEL, file) == N_PIXEL)
|
||||
{
|
||||
numero_righe++;
|
||||
istanze = (Istanza *)realloc(istanze, sizeof(Istanza) * (numero_righe + 1));
|
||||
// printf("Caricata nel sistema riga %d\n", numero_righe);
|
||||
}
|
||||
}
|
||||
|
||||
// Dataset set;
|
||||
(*set).size = numero_righe;
|
||||
(*set).istanze = istanze;
|
||||
|
||||
fclose(file);
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
void salva_dataset(const char *filename, Dataset *set)
|
||||
{
|
||||
FILE *file = fopen(filename, "wb");
|
||||
if (!file)
|
||||
{
|
||||
perror("Errore nell'apertura del file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (int indice_istanze = 0; indice_istanze < set->size; indice_istanze++)
|
||||
{
|
||||
fwrite(&set->istanze[indice_istanze].categoria, sizeof(byte), 1, file);
|
||||
fwrite(&set->istanze[indice_istanze].immagine, sizeof(byte), N_PIXEL, file);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
BIN
cifar-10/data_batch_1.bin
Normal file
BIN
cifar-10/data_batch_1.bin
Normal file
Binary file not shown.
61826
cifar-10/data_batch_2.bin
Normal file
61826
cifar-10/data_batch_2.bin
Normal file
File diff suppressed because one or more lines are too long
BIN
cifar-10/data_batch_3.bin
Normal file
BIN
cifar-10/data_batch_3.bin
Normal file
Binary file not shown.
BIN
cifar-10/data_batch_4.bin
Normal file
BIN
cifar-10/data_batch_4.bin
Normal file
Binary file not shown.
61291
cifar-10/data_batch_5.bin
Normal file
61291
cifar-10/data_batch_5.bin
Normal file
File diff suppressed because one or more lines are too long
BIN
cifar-10/test_batch.bin
Normal file
BIN
cifar-10/test_batch.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user