-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-display-sample.py
36 lines (26 loc) · 1.12 KB
/
test-display-sample.py
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
# test display
import keras
from keras.datasets import mnist
from displaysample import display_sample
(mnist_train_images, mnist_train_labels), (mnist_test_images, mnist_test_labels) = mnist.load_data()
from keras import backend as K
if K.image_data_format() == 'channels_first':
train_images = mnist_train_images.reshape(mnist_train_images.shape[0], 1, 28, 28)
test_images = mnist_test_images.reshape(mnist_test_images.shape[0], 1, 28, 28)
input_shape = (1, 28, 28)
else:
train_images = mnist_train_images.reshape(mnist_train_images.shape[0], 28, 28, 1)
test_images = mnist_test_images.reshape(mnist_test_images.shape[0], 28, 28, 1)
input_shape = (28, 28, 1)
train_images = train_images.astype('float32')
test_images = test_images.astype('float32')
train_images /= 255
test_images /= 255
train_labels = keras.utils.to_categorical(mnist_train_labels, 10)
test_labels = keras.utils.to_categorical(mnist_test_labels, 10)
num=1234
print(train_labels[num])
#Print the label converted back to a number
label = train_labels[num].argmax(axis=0)
image = train_images[num].reshape([28,28])
display_sample(image,label)