Keras: Vgg16 - Error in `decode_predictions'

I am trying to accomplish an image classification task using a pre-trained VGG16 model in Keras. The code I wrote following the instructions in the Keras app page is:

from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input, decode_predictions
import numpy as np

model = VGG16(weights='imagenet', include_top=True)
img_path = './train/cat.1.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

features = model.predict(x)
(inID, label) = decode_predictions(features)[0]

      

which is very similar to the code shown in this question already asked on the forum. But despite having include_top as True , I am getting the following error:

Traceback (most recent call last):
  File "vgg16-keras-classifier.py", line 14, in <module>
    (inID, label) = decode_predictions(features)[0]
ValueError: too many values to unpack

      

Any help would be deeply appreciated! Thank!

+3


source to share


1 answer


This is because (according to the function definition, which can be found here ), the function decode_predictions

returns a triple (class_name, class_description, score)

. This is why he claims there are too many values ​​to decompress.



+1


source







All Articles