2016-12-02 98 views
0

我跟着這個回購(https://github.com/iamgroot42/keras-finetuning),我已經完成了培訓。無法預測來自ImageNet類的輸入[Keras + Tensorflow]

現在,我想要預測我自己的數據集(包含2個類,鱷梨&芒果)和ImageNet集的輸入圖像。但預測結果總是返回索引0或1(我猜它是鱷梨或芒果),永遠不會從ImageNet返回一個類。例如。我想預測,從原來的ImageNet類來到一個iPod圖像,但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 indeximagenet 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]) 

大小)