参考资料
鱼书第三章:下载mnist数据集失败,403 Forbidden问题
将上述四个压缩包放入dataset文件夹中,注意dataset文件夹应在以下目录中
再运行以下代码
# coding: utf-8
import sys, os
sys.path.append(os.pardir) # 为了导入父目录的文件而进行的设定
import numpy as np
from dataset.mnist import load_mnist
from PIL import Imagedef img_show(img):pil_img = Image.fromarray(np.uint8(img))pil_img.show()(x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=False)img = x_train[0]
label = t_train[0]
print(label) # 5print(img.shape) # (784,)
img = img.reshape(28, 28) # 把图像的形状变为原来的尺寸
print(img.shape) # (28, 28)img_show(img)
能正常运行:
5
(784,)
(28, 28)
并出现图片