从 Keras 功能模型中获取类标签 [英] Get class labels from Keras functional model

查看:27
本文介绍了从 Keras 功能模型中获取类标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Keras 中有一个功能模型(来自 repo 示例的 Resnet50).我用 ImageDataGeneratorflow_from_directory 数据训练它并将模型保存到 .h5 文件.当我调用 model.predict 时,我得到一个类概率数组.但我想将它们与类标签(在我的情况下 - 文件夹名称)相关联.我怎样才能得到它们?我发现我可以使用 model.predict_classesmodel.predict_proba,但是我在 Functional 模型中没有这些函数,只有在 Sequential 中.

I have a functional model in Keras (Resnet50 from repo examples). I trained it with ImageDataGenerator and flow_from_directory data and saved model to .h5 file. When I call model.predict I get an array of class probabilities. But I want to associate them with class labels (in my case - folder names). How can I get them? I found that I could use model.predict_classes and model.predict_proba, but I don't have these functions in Functional model, only in Sequential.

推荐答案

y_prob = model.predict(x) 
y_classes = y_prob.argmax(axis=-1)

按照此处的建议.

这篇关于从 Keras 功能模型中获取类标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆