【问题标题】:Where are the images in the MNIST data array?MNIST 数据数组中的图像在哪里?
【发布时间】:2018-10-24 04:35:37
【问题描述】:

我正在尝试查看用于机器学习的 MNIST 数据集。在 Tensorflow 中,可以使用

导入 MNIST 数据集
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
full_data_x = mnist.train.images

但是,当我尝试使用 80x80 的数据数组来可视化时

test_x, test_y = mnist.test.images, mnist.test.labels
plt.gray()
plt.imshow(1-test_x[80:160,80:160])

这样看起来真的很奇怪:

如何提取实际手写数字的图像,就像它们在互联网上显示的那样:

我看到了类似的问题,例如this。但是,我会特别感兴趣 where 在训练数据数组中图像实际上是隐藏的。我知道张量流模块提供了显示图像的功能。

【问题讨论】:

标签: python tensorflow mnist


【解决方案1】:

我想我现在明白了你的问题,这与我认为重复的问题有点不同。

图像不一定是隐藏的。该列表的每个索引本身就是一个图像:

num_test_images, num_train_images = len(mnist.test.images), len(mnist.train.images)

size_of_first_test_image, size_of_first_train_image =  len(mnist.test.images[0]), len(mnist.train.images[0])

print num_test_images, num_train_images
print size_of_first_test_image, size_of_first_train_image

输出:

10000 55000
784 784

可以看到训练和测试图像的数量就是每个mnist列表的长度。每个图像都是一个大小为 784 的平面数组。您必须自己重塑它才能使用 numpy 或类似的东西显示它。

试试这个:

first_test_image = np.array(mnist.test.images[0], dtype='float')
reshaped_image = first_image.reshape((28, 28))

【讨论】:

  • 啊,我明白了!这正是我理解数据集所缺少的信息。感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-23
  • 2011-02-25
  • 2012-07-05
  • 2018-03-12
  • 1970-01-01
  • 1970-01-01
  • 2022-01-01
相关资源
最近更新 更多