如何使用keras在神经网络中打印预测类的名称? [英] How to print the names of predicted classes in Neural Network using keras?

查看:149
本文介绍了如何使用keras在神经网络中打印预测类的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在keras中使用了预先训练的模型,最终预测类索引是一些整数值,但是我似乎不明白如何打印这些类的名称?

I am using a pre-trained model in keras and ended up predicting the class indices to be some integer values, but I don't seem to understand how do I print the names those classes?

我正在使用的模型是ResNet 50.

The model I am using is ResNet 50.

仍然无法弄清楚,对我来说,获得编辑答复是非常重要的.

Still can't figure it out and it's really important for me to get it answered to editing it.

推荐答案

如果您不使用imagenet数据,而是按照自己的方式进行重新训练:使用ImageDataGenerator的keras的flow_from_directory时,它将方便地保存以下标签:您在.class_indices中可访问的dict中的文件夹!字典的值与model.predict输出的位置相对应.

If you are not using imagenet data but retrain on your own set: When using keras' flow_from_directory of an ImageDataGenerator, it conveniently saves the labels of your folders in a dict accessible within .class_indices! The values of the dict correspond to the positions of your model.predict output.

粗暴的例子:

preds = model.predict(x)
for cls in training_generator.class_indices:
    print(cls+": "+preds[0][training_generator.class_indices[cls]])

另请参阅: https://keras.io/preprocessing/image/

这篇关于如何使用keras在神经网络中打印预测类的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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