簡體   English   中英

Keras 預訓練的 Xception 模型總是給出預測“sewing_machine”

[英]Keras pretrained Xception model always gives the prediction 'sewing_machine'

我正在使用 Keras 預訓練模型“Xception”進行圖像識別。 然而,無論我給 Xception 什么圖片,預測總是:

預測:[[('n04179913', 'sewing_machine', 1.0), ('n15075141,token_tissue', 0.0), ('n02317335',​​ 'starfish', 0.0), ('n02389026,'.0rel) 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))

按 x/255 標准化圖像。 就在預測函數調用之前 根據我的理解,Xception 模塊是在標准化強度上訓練的。 我遇到了同樣的問題。 因此,我通過將像素強度除以 255 來標准化像素強度。您可以嘗試相同的方法。 我希望它有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM