【发布时间】:2017-02-26 17:04:19
【问题描述】:
大家好,我一直在从事一个 tensorflow 项目,我想从 MNIST 数据库中获取测试图像。以下是将原始数据(ubyte?)转换为 2d numpy 的代码要点:
from PIL import Image
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot = True)
def gen_image(arr):
two_d = np.reshape(arr, (28, 28))
img = Image.fromarray(two_d, 'L')
return img
batch_xs, batch_ys = mnist.test.next_batch(1)
gen_image(batch_xs[0]).show()
但是,当 img 显示 here 时,它看起来不像是一个正常的数字,所以我想我一定是在某个地方搞砸了,但除了 numpy 数组被重新整形为 [28, 28] 时无法查明它来自 [784]。有什么线索吗?
编辑:所以很明显,如果我使用 matplotlib 而不是 PIL 它工作正常:
【问题讨论】:
-
我读过那篇文章,但它并没有真正解释我的图像看起来不像数字?
-
嗯,很明显,如果我使用 matplotlib 而不是 PIL,图像将正确显示......我想知道为什么。无论如何,我会暂时使用 matplotlib
标签: python numpy tensorflow mnist