Pra*_*aha 5 classification python-2.7 conv-neural-network keras
我正在尝试使用 Keras 中预训练的 VGG16 模型执行图像分类任务。我按照Keras 应用程序页面中的说明编写的代码是:
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]
Run Code Online (Sandbox Code Playgroud)
这与论坛中已经提出的这个问题中显示的代码非常相似。但尽管include_top参数为True,我收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!谢谢!