-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMNISTConvolutionExemple.py
More file actions
65 lines (47 loc) · 1.75 KB
/
MNISTConvolutionExemple.py
File metadata and controls
65 lines (47 loc) · 1.75 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
# -*- coding: utf-8 -*-
# Chargement des données de MNIST
import pickle, gzip
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
fichier_donnees = gzip.open(r"mnist.pkl.gz", 'rb')
donnees_ent, donnees_validation, donnees_test = pickle.load(fichier_donnees, encoding='latin1')
fichier_donnees.close()
for i in range(3):
print("Classe de l'image",i,":",donnees_ent[1][i])
image_applatie = donnees_ent[0][i]
une_image = image_applatie.reshape(28, 28)
plt.imshow(une_image, cmap = mpl.cm.binary, interpolation="nearest")
plt.axis("off")
plt.show()
plt.figure()
im = plt.imshow(np.reshape(donnees_ent[0][0], newshape=(28,28)),
interpolation='none', vmin=0, vmax=1, aspect='equal');
ax = plt.gca();
# Major ticks
ax.set_xticks(np.arange(0, 27, 1));
ax.set_yticks(np.arange(0, 27, 1));
# Labels for major ticks
ax.set_xticklabels(np.arange(0, 27, 1));
ax.set_yticklabels(np.arange(0, 27, 1));
# Minor ticks
ax.set_xticks(np.arange(-.5, 28, 1), minor=True);
ax.set_yticks(np.arange(-.5, 28, 1), minor=True);
# Gridlines based on minor ticks
ax.grid(which='minor', color='w', linestyle='-', linewidth=2)
image = np.reshape(donnees_ent[0][0], newshape=(28,28))
fig, ax = plt.subplots()
fig = plt.figure(figsize=(10,10))
im = ax.imshow(image,interpolation='none', vmin=0, vmax=1, aspect='equal')
ax.set_xticks(np.arange(0, 27, 1));
ax.set_yticks(np.arange(0, 27, 1));
ax.set_xticklabels(np.arange(0, 27, 1));
ax.set_yticklabels(np.arange(0, 27, 1));
# Loop over data dimensions and create text annotations.
for i in range(28):
for j in range(28):
text = ax.text(j, i, image[i, j],
ha="center", va="center", color="w",fontsize="medium")
ax.set_title("Image")
#fig.tight_layout()
plt.show()