我正在尝试使用Keras中预先训练的VGG16模型执行图像分类任务。我按照Keras application page中的说明编写的代码是:
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]
与论坛中已经提到的this question中显示的代码非常相似。但是,尽管 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
任何帮助都将深表感谢!谢谢!
答案 0 :(得分:2)
这是因为(根据可能找到的函数定义here)函数// if (seatNum != 201) { // optional, to neglect seat 201
System.out.print("Row: "); // yes, I am that lazy...
if (seatNum <= 0) {
System.out.println(1);
} else if ((seatNum <= 200) /* && (seatNum > 0) */) {
System.out.println(((seatNum - 1)/ 20) + 1);
} else /* if (seatNum > 200) */ {
System.out.println(((seatNum - 202) / 15) + 11);
}
// }
返回三元组decode_predictions
。这就是为什么它声称有太多值要解压缩。