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

后端 未结 1 1454
[愿得一人]
[愿得一人] 2020-12-20 06:36

I\'m using transfer learning method to use per-trained VGG19 model in Keras according to [this tutorial](https://towardsdatascience.com/keras-transfer-learning-for-beginners

相关标签:
1条回答
  • 2020-12-20 07:24

    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]])
    
    0 讨论(0)
提交回复
热议问题