import numpy as np
from PIL import Image
path='./mnist.npz'
f = np.load(path)
x_train, y_train = f['x_train'], f['y_train']
x_test, y_test = f['x_test'], f['y_test']
for i in range(x_train.shape[0]):
new_im = Image.fromarray(x_train[i,:,:])
new_im.save('./MNIST_zip/train/No:%d label:%d.png'%(i,y_train[i]))
for j in range(x_test.shape[0]):
new_im = Image.fromarray(x_test[j,:,:])
new_im.save('./MNIST_zip/test/No:%d label:%d.png'%(j,y_test[j]))
print('completed')
from PIL import Image
path='./mnist.npz'
f = np.load(path)
x_train, y_train = f['x_train'], f['y_train']
x_test, y_test = f['x_test'], f['y_test']
for i in range(x_train.shape[0]):
new_im = Image.fromarray(x_train[i,:,:])
new_im.save('./MNIST_zip/train/No:%d label:%d.png'%(i,y_train[i]))
for j in range(x_test.shape[0]):
new_im = Image.fromarray(x_test[j,:,:])
new_im.save('./MNIST_zip/test/No:%d label:%d.png'%(j,y_test[j]))
print('completed')