AI:VGG16神经网络分类预测

假设一张图片是这样的:

Python代码:

import numpy as np
from keras.preprocessing import image
from keras.applications.vgg16 import VGG16, preprocess_input, decode_predictions


if __name__ == '__main__':
    model = VGG16(include_top=True, input_tensor=None, input_shape=None, pooling=None, classes=1000)
    img = image.load_img('./p.jpg', color_mode='rgb', target_size=(224, 224))
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)

    preds = model.predict(preprocess_input(x))

    results = decode_predictions(preds, top=5)[0]
    for result in results:
        print(result)

VGG16神经网络预测的结果:

('n02504458', 'African_elephant', 0.86725783)
('n01871265', 'tusker', 0.12646084)
('n02504013', 'Indian_elephant', 0.005013223)
('n02422106', 'hartebeest', 0.00031558485)
('n02437312', 'Arabian_camel', 0.00021430758)

预测最高概率是0.86725783,预测命中非洲象。

发布了1029 篇原创文章 · 获赞 987 · 访问量 336万+

猜你喜欢

转载自blog.csdn.net/zhangphil/article/details/103190138