tensorflowでMNISTデータセットを使う
python
from tensorflow.examples.tutorials.mnist import input_data
import cv2
import numpy as np
# なかったら自動でダウンロードされる
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
# 訓練
tr = mnist.train.images
# 試験
te = mnist.test.images
# 評価
va = mnist.validation.images
# (55000, 784)
print(tr.shape)
# (10000, 784)
print(te.shape)
# (5000, 784)
print(va.shape)
# (10000, 784) -> (10000, 28, 28)
te = np.reshape(te, (-1, 28, 28))
# numpyでsave
np.save('example.npy', te)
# numpyでload
te = np.load('example.npy')
# 7が表示される
cv2.imshow('', te[0,:,:])
cv2.waitKey(0)
MNISTの構成
mnist.train
mnist.test
mnist.validation
mnist.(..).images
mnist.(..).labels