I'm using Keras pretrained model 'Xception' to do image recognition. However, no matter what picture I give Xception, the predictions are always:
Predicted: [[('n04179913', 'sewing_machine', 1.0), ('n15075141, toilet_tissue', 0.0), ('n02317335', 'starfish', 0.0), ('n02389026, sorrel', 0.0), ('n02364673', 'guinea_pig', 0.0)]]
Is there anything wrong with my code?
My code is:
from tensorflow.contrib.keras import applications as app
from tensorflow.contrib.keras import preprocessing as pp
import numpy as np
model = app.Xception(weights='imagenet', include_top=True)
img_path = 'test123.jpg'
img = pp.image.load_img(path=img_path, target_size=(299, 299))
x = pp.image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = app.xception.preprocess_input(x)
preds = model.predict(x)
print('Predicted:', app.xception.decode_predictions(preds))
Normalize the image by x/255. just before predict function call As per my understanding, Xception module is trained on normalized intensities. I faced the same problem. So, i normalized the pixel intensities by dividing them by 255. You can try the same. I hope it helps.