python - 如何使用 ImageDataGenerator 绘制验证图像?
问题描述
我正在尝试建立一个图像分类模型,但不知道如何绘制具有预测类别(和概率)的验证图像,如本指南中所示:
https://www.tensorflow.org/tutorials/images/hub_with_keras#check_the_predictions
当我使用 ImageDataGenerator 时,我可以获得有关预测类别和概率的信息,但我无法获得图像本身。
plt.figure(figsize=(10,9))
for n in range(30):
plt.subplot(6,5,n+1)
plt.imshow(image_batch[n])
plt.title(labels_batch[n])
plt.axis('off')
_ = plt.suptitle("Model predictions")
我得到 ValueError: could not broadcast input array from shape (400,80,80,3) into shape (400)
我知道问题出在 -> image_batch[n]
请告诉我如何将有关图像的信息传递给 imshow()。
我使用的图像生成器的 PS 代码:
img_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1/255)
image_batch = img_generator.flow_from_directory(
path,
target_size=(size, size),
color_mode='rgb',
class_mode='categorical',
batch_size=batch_size
)
解决方案
推荐阅读
- powershell - 在循环中重复增加 DateTime 值?
- python - 无法弄清楚TIC TAC TOE中的问题是什么,下面正文中的问题详细描述[Python 3]
- javascript - GTM 根据现有变量创建新变量(WPForms 跟踪)
- java - 如何使用 Swing 在按钮内打印 void 方法?
- flutter - 如何用 backBoutton 解除 showDialog?
- html - 我不明白 ~ * css 选择器组合
- java - 为什么 SOAP-UI 在 5.6.0 版中存在 SSL 握手问题,但 5.5.0 版却运行良好?
- node.js - 如何隐藏/屏蔽heroku路由器日志
- python - 如何解决通过python客户端插入的大查询中的重复字段错误?
- android - Android AOSP 锁屏旋转