Keras:使用InceptionV3、ResNet50模型进行图片分类

Keras:使⽤InceptionV3、ResNet50模型进⾏图⽚分类
渗透压力
版权声明:本⽂为博主原创⽂章,未经博主允许不得转载。 blog.csdn/akadiao/article/details/80386115
⽤Keras构建⽹络并使⽤其提供的预训练权重进⾏简单的图像分类.
其中decode_predictions()将结果解码为元组列表,内容包括(类别,描述,概率).
养老地产运营模式
使⽤Inc eptio nV3进⾏图⽚分类
幻想曲古筝#!/usr/bin/python
# coding:utf8
from keras.applications.inception_v3 import InceptionV3
from keras.applications.inception_v3 import decode_predictions
from keras.preprocessing import image
import numpy as np
import cv2
model = InceptionV3(weights='imagenet', include_top=True)
img_path = "bird1.jpg"用友华表cell插件
img = image.load_img(img_path, target_size=(299, 299))
img = image.img_to_array(img) / 255.0
img = np.expand_dims(img, axis=0)  # 为batch添加第四维
predictions = model.predict(img)
print('Predicted:', decode_predictions(predictions, top=3))
description = decode_predictions(predictions, top=3)[0][0][1]
src = cv2.imread(img_path)
cv2.putText(src, description, (50,50), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,0,0), 2)
cv2.imshow("Predicted", src)
cv2.waitKey()
输出:
('Predicted:', [[(u'n02110185', u'Siberian_husky', 0.734093), (u'n02109961', u'Eskimo_dog', 0.17709365), (u'n02110063', u'malamute', 0.013321317
使⽤R esN et50进⾏图⽚分类
#!/usr/bin/python
# coding:utf8
from snet50 import ResNet50
from keras.preprocessing import image
from snet50 import preprocess_input, decode_predictions
import numpy as np
import cv2
model = ResNet50(weights='imagenet')
img_path = 'bird.jpg'
img = image.load_img(img_path, target_size=(224, 224))
img = image.img_to_array(img)
img = np.expand_dims(img, axis=0)
img = preprocess_input(img)
predictions = model.predict(img)
print('Predicted:', decode_predictions(predictions, top=3))
description = decode_predictions(predictions, top=3)[0][0][1]
src = cv2.imread(img_path)
cv2.putText(src, description, (50,50), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,0,0), 2)
cv2.imshow("Predicted", src)
cv2.waitKey()金钱的魔力教学设计
纪录片面条之路输出:
('Predicted:', [[(u'n01531178', u'goldfinch', 0.88929653), (u'n01537544', u'indigo_bunting', 0.0318476), (u'n01560419', u'bulbul', 0.024045745)]])

本文发布于:2024-09-21 22:40:35,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/453341.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:博主   包括   列表
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议