2017-05-16 1 views
3

Keras에서 미리 훈련 된 VGG16 모델을 사용하여 이미지 분류 작업을 수행하려고합니다. 이 코드는 내가 쓴 Keras application page의 지침에 따라입니다 :Keras : Vgg16 -`decode_predictions '의 오류

이미 포럼에 질문 this question에 표시된 코드와 매우 유사하다
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] 

. 그러나 진정한 include_top 매개 변수를 가진에도 불구하고, 나는 다음과 같은 오류가 점점 오전 :

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 

어떤 도움을 깊이 이해할 수있을 것이다! 감사!

답변

1

(함수 정의에 따라 here) 함수 decode_predictions은 트리플 (class_name, class_description, score)을 반환하기 때문입니다. 이것이 포장을 푸는 데 너무 많은 가치가 있다고 주장하는 이유입니다.

+1

답변 해 주셔서 감사합니다. 만약 결과가'result = decode_predictions (features)'를 사용한다면 실제로 출력은'[[(a1, b1, c1), ..., (a5, b5, c5)]]와 같은 또 다른 배열 안에 있습니다. . 따라서 최상위 결과를 얻으려면,'decode_predictions (features) [0] [0]' – Prabaha