Cannot predict the label for a single image with VGG19 in Keras

醉酒当歌 提交于 2019-11-29 12:27:35

decode_predictions is used for decoding predictions of a model according to the labels of classes in ImageNet dataset which has 1000 classes. However, your fine-tuned model has only 12 classes. Therefore, it does not make sense to use decode_predictions here. Surely, you must know what the labels for those 12 classes are. Therefore, just take the index of maximum score in the prediction and find its label:

# create a list containing the class labels
class_labels = ['class1', 'class2', 'class3', ...., 'class12']

# find the index of the class with maximum score
pred = np.argmax(class_labels, axis=-1)

# print the label of the class with maximum score
print(class_labels[pred[0]])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!