赞
踩
模型参数文件:
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()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。