当前位置:   article > 正文

Keras中利用训练好的vgg16预测图片类型_keras预测图片类型

keras预测图片类型
代码:
  1. from keras.applications.vgg16 import VGG16
  2. from keras.preprocessing import image
  3. from keras.applications.vgg16 import preprocess_input
  4. from keras.applications import imagenet_utils
  5. import numpy as np
  6. model = VGG16(weights='imagenet')
  7. img_path = 'E:\\timg.jpg'
  8. img = image.load_img(img_path, target_size=(224, 224))
  9. x = image.img_to_array(img)
  10. x = np.expand_dims(x, axis=0)
  11. x = preprocess_input(x)
  12. features = model.predict(x)
  13. print('Predicted:', imagenet_utils.decode_predictions(features, top=3)[0])
输出结果:预测结果是pizza,82%的概率
  1. E:\phthon35\python.exe I:/catsVSdogs1-master/catsVSdogs1-master/file01/ImagesPredict.py
  2. Predicted: [('n07873807', 'pizza', 0.82579499), ('n07583066', 'guacamole', 0.029104929), ('n07880968', 'burrito', 0.018119223)]
  3. Process finished with exit code 0


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/103905?site
推荐阅读
相关标签
  

闽ICP备14008679号