2016-12-02 3 views
0

이 레포 (https://github.com/iamgroot42/keras-finetuning)를 따랐으므로 교육을 완료했습니다.ImageNet 클래스의 입력을 예측할 수 없습니다. [Keras + Tensorflow]

이제 내 자신의 데이터 집합 (Avocado & 망고)과 ImageNet을 모두 포함하는 데이터 집합을 예측하고 싶습니다. 하지만 인덱스 0 또는 1 (항상 아보카도 또는 망고 같아요) 모두 반환하는 예측 결과, 결코 ImageNet에서 클래스를 반환합니다. 예 : 나는 ImageNet 원래 클래스에서 나온 아이팟 이미지를 예측하기 원하지만 model.predict (...)는 항상 0과

1을 반환 내 모델 labels.json :

["avocados", "mangos"] 

내 코드 예측을 위해 :

img = imresize(imread('ipod.png', mode='RGB'), (224, 224)).astype(np.float32) 
img[:, :, 0] -= 123.68 
img[:, :, 1] -= 116.779 
img[:, :, 2] -= 103.939 
img[:,:,[0,1,2]] = img[:,:,[2,1,0]] 
img = img.transpose((2, 0, 1)) 
img = np.expand_dims(img, axis=0) 
img = img.reshape(img.shape[0], n, n, n_chan) 

out = model.predict(img, batch_size=batch_size) 
pred = np.argmax(out, axis=1) 

print(pred) 

나를 도와 줄 사람이 있습니까?

+0

당신은 당신의 모델 정의를 게시 할 수 있습니까? –

+0

@ avijit-dasgupta 다음은 전체 스크립트입니다 : github.com/iamgroot42/keras-finetuning/blob/master/net.py –

답변

1

어쩌면 class index에서 imagenet labels 사이에 변환하면됩니까?

시도 :

from imagenet_utils import decode_predictions 

[...] 

img = imresize(imread('ipod.png', mode='RGB'), (224, 224)).astype(np.float32) 
img[:, :, 0] -= 123.68 
img[:, :, 1] -= 116.779 
img[:, :, 2] -= 103.939 
img[:,:,[0,1,2]] = img[:,:,[2,1,0]] 
img = img.transpose((2, 0, 1)) 
img = np.expand_dims(img, axis=0) 
img = img.reshape(img.shape[0], n, n, n_chan) 

out = model.predict(img, batch_size=batch_size) 
#add decoding line here to get the top 3 
print('Predicted:', decode_predictions(out, top=3)[0]) 

크기)

관련 문제