keras - 如何从我的测试数据生成器显示错误分类在 keras 中的图像?
问题描述
我正在使用图像数据生成器进行二进制分类。我已经建立了我的模型,现在我想显示按我的模式错误分类的图像。
我的代码如下。我正在尝试构建一个分类错误的图像和标签,然后从我的测试生成器中显示 100 个图像。
images = []
labels = []
for i in range(100):
img, label = next(val_generator)
img = img_to_array(img[i])
img = np.expand_dims(img, axis=0)
result = model.predict_classes(img)
if result != label[i]:
images.append(img)
labels.append(label)
我想显示图像[]。编码:
images[0]
images[0].reshape(-1)
img0 = array_to_img(images[0])
plt.plot(images[0])
我得到错误:
Traceback (most recent call last):
File "<ipython-input-723-c79b5280f8fc>", line 1, in <module>
img0 = array_to_img(images[0])
File "/home/idu/.local/lib/python3.6/site-packages/keras/preprocessing/image.py", line 184, in array_to_img
return image.array_to_img(x, data_format=data_format, scale=scale, **kwargs)
我认为这是关于从数组中重塑我的图像。如何显示错误分类的图像?谢谢!
File "/home/idu/.local/lib/python3.6/site-packages/keras_preprocessing/image/utils.py", line 257, in array_to_img
'Got array with shape: %s' % (x.shape,))
ValueError: Expected image array to have rank 3 (single image). Got array with shape: (1, 512, 512, 1)
解决方案
推荐阅读
- f# - 使用 F# 中插入的新项目制作 Map 的副本
- json - 如何存储渲染 React 组件所需的数据?
- android - 在活动应用程序崩溃之间传递一个字节 [] 但在片段之间传递相同的字节 [] 它运行良好
- python - 谷歌分析数据到熊猫数据框
- reactjs - 如何在 React Native 项目中使用 jsconfig.json
- google-analytics - 如何更改 GTM 标签列表的跟踪 ID
- html - position:sticky 允许粘性项目在滚动时离开屏幕
- javascript - 将 Javascript BLOB 编码更改为 ANSI 而不是 UTF-8
- django - 如何在 Django REST Framwork Serializer GET 返回中添加附加字段
- .htaccess - 禁止标题页 robots.txt