mirror of
https://github.com/augustin64/projet-tipe
synced 2025-01-23 15:16:26 +01:00
Add utils: count-labels
This commit is contained in:
parent
b30bedd375
commit
a57e908fe4
20
COMPTE_RENDU.md
Normal file
20
COMPTE_RENDU.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Compte rendu
|
||||
|
||||
### 22 Avril 2022 [b30bedd](https://github.com/julienChemillier/TIPE/commit/b30bedd375e23ec7c2e5b10acf397a10885d8b5e)
|
||||
Le réseau minimise la fonction d'erreur (différence entre sortie voulue et obtenue).
|
||||
Cela donne comme résultat une précision de 10.2% en moyenne soit à peine mieux qu'aléatoire.
|
||||
Chaque image renvoie les mêmes poids sur la dernière couche.
|
||||
Voici un tableau comparant la fréquence d'apparition de chaque chiffre et l'activation associée sur la dernière couche :
|
||||
|
||||
| Chiffre | Nombre d'occurences dans le set d'entraînement | Activation du neurone sortant | Rapport |
|
||||
| --- | --- | --- | --- |
|
||||
| 0 | 23692 | 0.483112 | 49040 |
|
||||
| 1 | 26968 | 0.508133 | 53072 |
|
||||
| 2 | 23832 | 0.492748 | 48365 |
|
||||
| 3 | 24524 | 0.536703 | 45693 |
|
||||
| 4 | 23368 | 0.532142 | 43913 |
|
||||
| 5 | 21684 | 0.501488 | 43239 |
|
||||
| 6 | 23672 | 0.518371 | 45666 |
|
||||
| 7 | 25060 | 0.499134 | 50206 |
|
||||
| 8 | 23404 | 0.512515 | 45665 |
|
||||
| 9 | 23796 | 0.556504 | 42759 |
|
@ -61,6 +61,27 @@ int* read_mnist_images_parameters(char* filename) {
|
||||
return tab;
|
||||
}
|
||||
|
||||
uint32_t read_mnist_labels_nb_images(char* filename) {
|
||||
FILE *ptr;
|
||||
|
||||
ptr = fopen(filename, "rb");
|
||||
|
||||
uint32_t magic_number;
|
||||
uint32_t number_of_images;
|
||||
|
||||
fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
||||
magic_number = swap_endian(magic_number);
|
||||
|
||||
if (magic_number != 2049) {
|
||||
printf("Incorrect magic number !\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fread(&number_of_images, sizeof(uint32_t), 1, ptr);
|
||||
number_of_images = swap_endian(number_of_images);
|
||||
|
||||
return number_of_images;
|
||||
}
|
||||
|
||||
// Lit un set de données images sous format de la base de données MNIST
|
||||
int*** read_mnist_images(char* filename) {
|
||||
|
@ -9,6 +9,7 @@
|
||||
uint32_t swap_endian(uint32_t val);
|
||||
int** read_image(unsigned int width, unsigned int height, FILE* ptr);
|
||||
int* read_mnist_images_parameters(char* filename);
|
||||
int* read_mnist_labels_parameters(char* filename);
|
||||
int*** read_mnist_images(char* filename);
|
||||
unsigned int* read_mnist_labels(char* filename);
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "neural_network.c"
|
||||
#include "neuron_io.c"
|
||||
#include "mnist.c"
|
||||
|
||||
/*
|
||||
Contient un ensemble de fonctions utiles pour le débogage
|
||||
@ -16,6 +17,8 @@ void help(char* call) {
|
||||
printf("\t\t--reseau | -r [FILENAME]\tFichier contenant le réseau de neurones.\n");
|
||||
printf("\tprint-biais:\n");
|
||||
printf("\t\t--reseau | -r [FILENAME]\tFichier contenant le réseau de neurones.\n");
|
||||
printf("\tcount-labels:\n");
|
||||
printf("\t\t--labels | -l [FILENAME]\tFichier contenant les labels.\n");
|
||||
printf("\tcreer-reseau:\n");
|
||||
printf("\t\t--out | -o [FILENAME]\tFichier où écrire le réseau de neurones.\n");
|
||||
printf("\t\t--number | -n [int]\tNuméro à privilégier\n");
|
||||
@ -28,7 +31,7 @@ void print_biais(char* filename) {
|
||||
for (int i=1; i < reseau->nb_couches -1; i++) {
|
||||
printf("Couche %d\n", i);
|
||||
for (int j=0; j < reseau->couches[i]->nb_neurones; j++) {
|
||||
printf("Couche %d\tNeurone %d\tBiais: %0.1f\n", i, j, reseau->couches[i]->neurones[j]->biais);
|
||||
printf("Couche %d\tNeurone %d\tBiais: %f\n", i, j, reseau->couches[i]->neurones[j]->biais);
|
||||
}
|
||||
}
|
||||
suppression_du_reseau_neuronal(reseau);
|
||||
@ -42,7 +45,7 @@ void print_poids(char* filename) {
|
||||
for (int j=0; j < reseau->couches[i]->nb_neurones; j++) {
|
||||
printf("Couche %d\tNeurone %d\tPoids: [", i, j);
|
||||
for (int k=0; k < reseau->couches[i+1]->nb_neurones; k++) {
|
||||
printf("%0.01f, ", reseau->couches[i]->neurones[j]->poids_sortants[k]);
|
||||
printf("%f, ", reseau->couches[i]->neurones[j]->poids_sortants[k]);
|
||||
}
|
||||
printf("]\n");
|
||||
}
|
||||
@ -50,6 +53,27 @@ void print_poids(char* filename) {
|
||||
suppression_du_reseau_neuronal(reseau);
|
||||
}
|
||||
|
||||
void count_labels(char* filename) {
|
||||
uint32_t number_of_images = read_mnist_labels_nb_images(filename);
|
||||
|
||||
unsigned int* labels = malloc(sizeof(unsigned int)*number_of_images);
|
||||
labels = read_mnist_labels(filename);
|
||||
|
||||
unsigned int* tab[10];
|
||||
|
||||
for (int i=0; i < 10; i++) {
|
||||
tab[i] = 0;
|
||||
}
|
||||
|
||||
for (int i=0; i < number_of_images; i++) {
|
||||
tab[(int)labels[i]]++;
|
||||
}
|
||||
|
||||
for (int i=0; i < 10; i++) {
|
||||
printf("Nombre de %d: %d\n", i, tab[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void creer_reseau(char* filename, int sortie) {
|
||||
Reseau* reseau = malloc(sizeof(Reseau));
|
||||
Couche* couche;
|
||||
@ -152,15 +176,23 @@ int main(int argc, char* argv[]) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (! out) {
|
||||
printf("Pas de fichier spécifié, défaut: '.cache/reseau.bin'\n");
|
||||
out = ".cache/reseau.bin";
|
||||
} else if (! strcmp(argv[1], "count-labels")) {
|
||||
char* labels = NULL;
|
||||
int i = 2;
|
||||
while (i < argc) {
|
||||
if ((! strcmp(argv[i], "--labels"))||(! strcmp(argv[i], "-l"))) {
|
||||
labels = argv[i+1];
|
||||
i += 2;
|
||||
} else {
|
||||
printf("%s : Argument non reconnu\n", argv[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (n == -1) {
|
||||
printf("Pas de numéro spécifié, défaut: 0\n");
|
||||
n = 0;
|
||||
if (! labels) {
|
||||
printf("Pas de fichier spécifié, défaut: 'data/mnist/train-labels-idx1-ubyte'\n");
|
||||
labels = "data/mnist/train-labels-idx1-ubyte";
|
||||
}
|
||||
creer_reseau(out, n);
|
||||
count_labels(labels);
|
||||
exit(1);
|
||||
}
|
||||
printf("Option choisie non reconnue: %s\n", argv[1]);
|
||||
|
Loading…
Reference in New Issue
Block a user