Keras预训练Xception模型总是给出预测' sewing_machine'

时间:2017-09-14 02:04:34

标签: machine-learning tensorflow deep-learning keras pre-trained-model

我使用的是Keras预训练模型' Xception'做图像识别。但是,无论我给出什么样的Xception,预测都是:

  

预测:[[(' n04179913',' sewing_machine',1.0),(' n15075141,   toilet_tissue',0.0),(' n02317335',' starfish',0.0),(' n02389026,   栗色',0.0),(' n02364673',' guinea_pig',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))

1 个答案:

答案 0 :(得分:-1)

按 x/255 对图像进行标准化。就在预测函数调用之前

相关问题