问题描述
我在Keras中有一个功能模型(来自repo示例的Resnet50).我使用ImageDataGenerator
和flow_from_directory
数据对其进行了训练,并将模型保存到了.h5
文件中.当我调用model.predict
时,我得到了一系列的类概率.但是我想将它们与类标签(在我的情况下-文件夹名称)相关联.我怎样才能得到它们?我发现可以使用model.predict_classes
和model.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功能模型获取类标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!