aggiustamento codice e libreria
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define N_PIXEL 3072 // 1024 pixel * 3 (R, G, B)
|
||||
#define N_INPUTS 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;
|
||||
@@ -9,8 +9,8 @@ typedef unsigned char byte;
|
||||
// Singola istanza del dataset.
|
||||
typedef struct
|
||||
{
|
||||
byte categoria;
|
||||
byte immagine[N_PIXEL];
|
||||
byte classificazione;
|
||||
byte dati[N_INPUTS];
|
||||
} Istanza;
|
||||
|
||||
// Questo tipo fornisce il vettore delle istanze e il size (dimensione) del vettore
|
||||
@@ -38,9 +38,9 @@ Dataset *get_dataset(char *path)
|
||||
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)
|
||||
while (fread(&istanze[numero_righe].classificazione, sizeof(byte), 1, file) == 1)
|
||||
{
|
||||
if (fread(istanze[numero_righe].immagine, sizeof(byte), N_PIXEL, file) == N_PIXEL)
|
||||
if (fread(istanze[numero_righe].dati, sizeof(byte), N_INPUTS, file) == N_INPUTS)
|
||||
{
|
||||
numero_righe++;
|
||||
istanze = (Istanza *)realloc(istanze, sizeof(Istanza) * (numero_righe + 1));
|
||||
@@ -57,7 +57,7 @@ Dataset *get_dataset(char *path)
|
||||
return set;
|
||||
}
|
||||
|
||||
void salva_dataset(const char *filename, Dataset *set)
|
||||
/* void salva_dataset(const char *filename, Dataset *set)
|
||||
{
|
||||
FILE *file = fopen(filename, "wb");
|
||||
if (!file)
|
||||
@@ -68,9 +68,9 @@ void salva_dataset(const char *filename, Dataset *set)
|
||||
|
||||
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);
|
||||
fwrite(&set->istanze[indice_istanze].classificazione, sizeof(byte), 1, file);
|
||||
fwrite(&set->istanze[indice_istanze].dati, sizeof(byte), N_INPUTS, file);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
} */
|
||||
Reference in New Issue
Block a user