我正在使用tensorflow导入一些MNIST输入数据。我按照这个教程进行了操作...https://www.tensorflow.org/get_started/mnist/beginners
我这样导入它们...
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
我希望能够显示训练集中的任何图像。我知道这些图像的位置是mnist.train.images
,因此我尝试访问第一张图像并像这样进行显示...
with tf.Session() as sess:
#access first image
first_image = mnist.train.images[0]
first_image = np.array(first_image, dtype='uint8')
pixels = first_image.reshape((28, 28))
plt.imshow(pixels, cmap='gray')
我试图将该图像转换为28x28的numpy数组,因为我知道每个图像是28x28像素。
然而,当我运行代码时,我得到了以下结果...
显然我做错了什么。当我打印矩阵时,一切似乎看起来很好,但我认为我错误地改变了形状。
np
,mnist
,plt
等内容,以便搜索快速答案的人可以快速复制和粘贴您所提供的代码。谢谢。 - Somo S.