【问题标题】:Keras Inception-V3 model predictions way offKeras Inception-V3 模型预测遥遥无期
【发布时间】:2017-11-07 19:05:55
【问题描述】:

因此,我运行了使用 inception-v3 模型的 Keras 示例代码,但预测结果还差得很远。我想权重有错误。有人知道为什么会这样吗?

我正在使用: Keras 2.0.4、Python 3.5(64 位)

https://github.com/fchollet/keras/blob/master/keras/applications/inception_v3.py

这是我正在运行的代码:

import numpy as np
from keras.applications.inception_v3 import InceptionV3
from keras.preprocessing import image
from keras.applications.imagenet_utils import preprocess_input, decode_predictions

if __name__ == '__main__':
    model = InceptionV3(include_top=True, weights='imagenet')

    img_path = 'elephant.jpg'
    img = image.load_img(img_path, target_size=(299, 299))
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)

    x = preprocess_input(x)

    preds = model.predict(x)
    print('Predicted:', decode_predictions(preds))

给出的结果是:

Predicted: [[('n01924916', 'flatworm', 0.99995065), ('n03047690', 'clog', 4.9389007e-05), ('n04366367', 'suspension_bridge', 1.075191e-08), ('n01665541', 'leatherback_turtle', 2.5111552e-10), ('n03950228', 'pitcher', 6.6290827e-11)]]

当我通过 ResNet50 模型运行相同的图像时,它会给出以下结果:

Predicted: [[('n02504458', 'African_elephant', 0.59942758), ('n01871265', 'tusker', 0.33637413), ('n02504013', 'Indian_elephant',
0.061940487), ('n02397096', 'warthog', 0.0016048651), ('n02396427', 'wild_boar', 0.00016479047)]]

编辑

我在 inception-v3 模型上测试了其他图像,它对每个不同的图像都给出了相同的预测。任何有关该问题的见解都将不胜感激。

【问题讨论】:

    标签: python-3.x machine-learning neural-network deep-learning keras


    【解决方案1】:

    InceptionResNet 具有不同的预处理功能。为了预处理Inception 的输入,试试这个函数:

    def preprocess_input(x):
        x /= 255.
        x -= 0.5
        x *= 2.
        return x
    

    【讨论】:

      【解决方案2】:

      你必须从xception模块导入preprocess_input

      from keras.applications.xception import preprocess_input
      

      或致电preprocess_input(images, mode='tf')

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-14
        • 2016-08-23
        • 1970-01-01
        • 1970-01-01
        • 2022-09-25
        • 2018-01-23
        相关资源
        最近更新 更多