-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter16_MNISTData.py
More file actions
40 lines (26 loc) · 903 Bytes
/
Copy pathChapter16_MNISTData.py
File metadata and controls
40 lines (26 loc) · 903 Bytes
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
from keras.datasets import mnist
from keras.utils import np_utils
import numpy
import sys
import tensorflow as tf
import matplotlib.pyplot as plt
seed = 0
numpy.random.seed(seed)
tf.set_random_seed(seed)
(X_train, Y_class_train), (X_test, Y_class_test) = mnist.load_data()
print("학습셋 이미지 수: %d 개" % (X_train.shape[0]))
print("테스트셋 이미지 수: %d 개" % (X_test.shape[0]))
plt.imshow(X_train[0], cmap='Greys')
plt.show()
for x in X_train[0]:
for i in x:
sys.stdout.write('%d\t' % i)
sys.stdout.write('\n')
X_train = X_train.reshape(X_test.shape[0], 784)
X_train = X_train.astype('float64')
X_train = X_train / 255
X_test = X_test.reshape(X_test.shape[0], 784).astype('float64') / 255
print("class : %d" % (Y_class_train[0]))
Y_train = np_utils.to_categorical(Y_class_train, 10)
Y_test = np_utils.to_categorical(Y_class_test, 10)
print(Y_train[0])