我正在使用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