-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtf2_chiffres_data.py
More file actions
67 lines (45 loc) · 1.69 KB
/
tf2_chiffres_data.py
File metadata and controls
67 lines (45 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
# Récupération des données
(X_train_data, Y_train_data), (X_test_data, Y_test_data) = mnist.load_data()
# Affichage d'un chiffre (données d'apprentissage)
def affiche_chiffre_train(i):
plt.imshow(X_train_data[i], cmap='Greys')
plt.title('Attendu %d' % Y_train_data[i], fontsize=30)
plt.tight_layout()
# plt.savefig('tf2-chiffre-train-%d.png' %i)
plt.show()
return
# for i in range(10):
# affiche_chiffre_train(i)
# Taille des données
print("Données d'apprentissage brutes X", X_train_data.shape)
print("Données d'apprentissage brutes Y", Y_train_data.shape)
N = X_train_data.shape[0] # 60 000 données
print("Nombre de données d'apprentissage :", N)
print("Taille d'une image :", X_train_data[0].shape)
print("Première image :\n", X_train_data[0])
# Mise sous forme de vecteur
X_train = np.reshape(X_train_data,(N,784))
# Normalisation (on se ramène entre 0 et 1)
X_train = X_train/255
print("Taille d'un vecteur :", X_train[0].shape)
print("Premièr vecteur image :\n", X_train[0])
# Résultat attendu
Y_train = to_categorical(Y_train_data, num_classes=10)
print("Résultat brut attendu pour la premier chiffre :", Y_train_data[0])
print("Résultat sous forme de liste :", Y_train[0])
# Pour le cours
# Affichage d'un chiffre (données de test)
def affiche_chiffre_test(i):
plt.imshow(X_test_data[i], cmap='Greys')
plt.title('Attendu %d' % Y_test_data[i])
plt.tight_layout()
# plt.savefig('tf2-chiffre-test-%d.png' %i)
plt.show()
return
for i in range(5):
affiche_chiffre_test(i)