importcv2importnumpyasnpfromlabelsimportLABEL_MAP# 1000 labels in imagenet dataset# caffe model, googlenet agloweights="bvlc_googlenet.caffemodel"protxt="bvlc_googlenet.prototxt"# read caffe model from disknet=cv2.dnn.readNetFromCaffe(protxt,weights)# create inputimage=cv2.imread("MY_TEST/ocean-liner.jpg")blob=cv2.dnn.blobFromImage(image,1.0,(224,224),(104,117,123),False,crop=False)result=np.copy(image)# run!net.setInput(blob)out=net.forward()# output probability, find the right indexout=out.flatten()classId=np.argmax(out)confidence=out[classId]# time costt,_=net.getPerfProfile()label='cost time: %.2f ms'%(t*1000.0/cv2.getTickFrequency())cv2.putText(result,label,(0,20),cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,255,0),2)# render on imagelabel='%s: %.4f'%(LABEL_MAP[classId]ifLABEL_MAPelse'Class #%d'%classId,confidence)cv2.putText(result,label,(0,60),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,255),2)show_img=np.hstack((image,result))# normal codes in opencvcv2.imshow("Image",show_img)cv2.waitKey(0)