首页 > 编程语言 > 详细

利用python中的库文件简单的展示mnist 中的数据图像

时间:2019-09-16 17:04:56      阅读:61      评论:0      收藏:0      [点我收藏+]
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)
#flatten参数为True的含义是展开输入图像(变成784个元素构成的一维数组)如果设置成False则为1*28*28的三维数组。  normalize为False时表示将输入图像正规化为0.0~0.1的值,为True时会保持原来的像素0~255.one_hot_label设置是否将标签保存为onehot表示(one-hot representation)。 one-hot表示是仅正确解标签为1,其余 皆为0的数组,就像[0,0,1,0,0,0,0,0,0,0]这样。当one_hot_label为False时, 只是像7、2这样简单保存正确解标签;当one_hot_label为True时,标签则 保存为one-hot表示。
  
def img_show(img):
    pil_img = Image.fromarray(np.uint8(img)) #将numpy数组的形状保存的图像转化为PIL用的数据对象。
    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)

技术分享图片

 

利用python中的库文件简单的展示mnist 中的数据图像

原文:https://www.cnblogs.com/hyan0913/p/11527757.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!