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

查看:58
本文介绍了从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天全站免登陆