jad*_*_96 5 machine-learning neural-network python-3.x deep-learning keras
因此,我运行了使用 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))
Run Code Online (Sandbox Code Playgroud)
给出的结果是:
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)]]
Run Code Online (Sandbox Code Playgroud)
当我通过 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)]]
Run Code Online (Sandbox Code Playgroud)
我在 inception-v3 模型上测试了其他图像,它对每个不同的图像给出了相同的预测。对这个问题的任何见解都将受到赞赏。
Inception并ResNet具有不同的预处理功能。为了预处理输入以Inception尝试此功能:
def preprocess_input(x):
x /= 255.
x -= 0.5
x *= 2.
return x
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2253 次 |
| 最近记录: |