小编cod*_*ord的帖子

plt.imshow()中图像数据的尺寸无效

我正在使用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()
Run Code Online (Sandbox Code Playgroud)

该代码给出的输出如下:

(28, 28, 1)
Run Code Online (Sandbox Code Playgroud)

和在plt.imshow(img_path)上的错误如下:

TypeError: Invalid dimensions for image data
Run Code Online (Sandbox Code Playgroud)

如何以png格式显示图像。救命!

matplotlib typeerror python-3.x mnist keras

5
推荐指数
2
解决办法
2324
查看次数

标签 统计

keras ×1

matplotlib ×1

mnist ×1

python-3.x ×1

typeerror ×1