import sys, os
sys.path.append('F:\ml\DL\source-code') #导入此路径中
from dataset.mnist import load_mnist
from PIL import Image
import numpy as np
(x_train, t_train), (x_test, t_test) = load_mnist(flatten = True, normalize = False, one_hot_label = False)
#True parameters flatten the meaning of an input image is expanded (784 becomes a one-dimensional array of elements constituting) If set to False, compared with a three-dimensional array of 28 * 28 *. normalize the input image represents a normalized value of 0.0 to 0.1, if the original pixel will remain 0 ~ 255.one_hot_label label settings will be saved onehot represents (onehot representation) when to True to False. represents only one-hot solution correct label 1, the rest of the array are all 0's, as [0,0,1,0,0,0,0,0,0,0] so. When one_hot_label is False, just as simple as 7,2 save the correct solution label; when one_hot_label to True, the label is saved as a one-hot representation.
DEF img_show (IMG):
pil_img = Image.fromarray (np.uint8 (IMG)) # converts an image stored in the shape data PIL numpy array is used for the object.
pil_img.show ()
IMG = x_train [0]
label = t_train [0]
Print (label)
Print (img.shape)
IMG = img.reshape (28, 28 )
Print (img.shape)
img_show (IMG)
5 (784,) (28, 28)