tensorflow - CNN 预测
问题描述
我已经使用训练集和验证集使用 Keras 构建并训练了一个模型。我想对未标记的数据进行预测,我有一个文件夹,其中包含 300 张狗、猫和马的图像。在预测中,我得到了每个类的概率。
如何获得最终输出,告诉/显示这 300 张图像中有多少属于每个类?
我上传模型
new_model = tf.keras.models.load_model('model')
然后我重新格式化测试图像
test_batches = train_datagen.flow_from_directory(
'test_images',
target_size=(224, 224),
batch_size=10,
classes = None,
class_mode= None)
然后我终于做出了预测
predictions = new_model.predict(test_batches, steps=30, verbose=0)
解决方案
import collections, numpy
collections.Counter(np.argmax(predictions, axis = 1))
推荐阅读
- javascript - 有没有办法通过单击 VSCode 上的按钮/快捷方式同时运行“tsc -watch”和“npm start”?
- android - FAILURE:构建失败并出现异常。应为 BEGIN_ARRAY,但为 BEGIN_OBJECT
- python - 如何将最相似的rand生成字符串作为主字符串,通过世代变异随机字符串以实现原始字符串?
- npm - 错误 403 - 尝试 npm install 时被禁止
- python - 在 Python 3.4 (Windows 10) 上升级后 pip 不起作用。如何降级?
- python - forward() 接受 1 个位置参数,但给出了 2 个
- sublimetext3 - 如何配置 Sublimes 首选的“打开包含文件夹”工具
- python - 如何在二维列表python中合并关闭点
- python - 如何在 Python 烧瓶中以特定间隔发送自动提醒电子邮件
- python - 派生类的存在是否会修改基类,即使派生类从未使用过?