当前位置:   article > 正文

OpenCV实战使用GoogLeNet实现图像分类_goolenet处理png

goolenet处理png

模型参数文件:
bvlc_googlenet.caffemodel
网络结构文件:
bvlc_googlenet.prototxt
分类文件:
label.txt

https://github.com/BVLC/caffe/tree/master/models/bvlc_googlenet

import numpy as np
import cv2

# image = cv2.imread('tower.jpg')
# image = cv2.imread('cat.jpg')
image = cv2.imread('dog.jpg')
config = 'model/bvlc_googlenet.prototxt'
model = 'model/bvlc_googlenet.caffemodel'

net = cv2.dnn.readNetFromCaffe(config, model)
blob = cv2.dnn.blobFromImage(image, 1, (224, 224), (104, 117, 123))
net.setInput(blob)
prob = net.forward()

classes = open('model/label.txt', 'rt').read().strip().split('\n')
rowIndex = np.argsort(prob[0])[::-1][0]

result = 'result:{}, {:.0f}%'.format(classes[rowIndex], prob[0][rowIndex]*100)
cv2.putText(image, result, (25, 45), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
cv2.imshow('result', image)
cv2.waitKey()
cv2.destroyAllWindows()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/926817
推荐阅读
相关标签
  

闽ICP备14008679号