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

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为True时表示将输入图像正规化为0.0~0.1的值,为False时会保持原来的像素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)

 

转载于:https://www.cnblogs.com/hyan0913/p/11527757.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值