【发布时间】:2019-07-06 22:34:46
【问题描述】:
我正在使用 mnist 数据集在 keras 背景中训练胶囊网络。 训练后,我想显示来自 mnist 数据集的图像。对于加载图像,使用 mnist.load_data()。数据存储为 (x_train, y_train),(x_test, y_test)。 现在,为了可视化图像,我的代码如下:
img_path = x_test[1]
print(img_path.shape)
plt.imshow(img_path)
plt.show()
代码给出的输出如下:
(28, 28, 1)
和 plt.imshow(img_path) 上的错误如下:
TypeError: Invalid dimensions for image data
如何以 png 格式显示图像。救命!
【问题讨论】:
-
您应该删除多余的渠道维度。试试
plt.imshow(np.squeeze(img_path)) -
@sdcbr 非常感谢。它有效..
-
这能回答你的问题吗? Showing an image with pylab.imshow()
标签: python-3.x matplotlib keras typeerror mnist