我正在使用 Keras 预训练模型“Xception”进行图像识别。然而,无论我给 Xception 什么图片,预测总是:
预测:[[('n04179913', 'sewing_machine', 1.0), ('n15075141, Toilet_tissue', 0.0), ('n02317335', 'starfish', 0.0), ('n02389026, sorrel', 0.0), (' n02364673', '几内亚猪', 0.0)]]
我的代码有什么问题吗?
我的代码是:
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))