import numpy as np
from matplotlib import pyplot as plt
from PIL import Image
import os
def load_data(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']
f.close()
return (x_train, y_train), (x_test, y_test)
(x_train ,y_train),( x_test ,y_test)=load_data("C:/Python35/学习深度/KARES/mnist.npz")
def showImg(mg,index):
#plt.imshow(mg[index])
#plt.show()
print(mg[index].dtype)
im = Image.fromarray(mg[index].astype(mg[index].dtype))
if os.path.isdir("./"+str(y_train[index]))==False:
os.mkdir("./"+str(y_train[index]))
im.save("./"+str(y_train[index])+"/"+str(index)+".jpg")
print(x_train.ndim)
print(x_train.shape[0])
for _is in range(x_train.shape[0]):
print(_is)
showImg(x_train, _is)
#print(x_train[_is])
print(y_train.shape)
print(x_test.shape)
print(y_test.shape)