我重新训练了基于Google Tensorflow对象检测API的对象检测模型。我将其导出为冻结的推理图。我想将其与CV2的DNN模块一起使用:
npm can't find a package.json file in your current directory
我收到此错误:cap = cv2.VideoCapture(URL)
cvNet = cv2.dnn.readNetFromTensorflow('graph.pb', 'graph.pbtxt')
while True:
ret, img = cap.read()
rows = img.shape[0]
cols = img.shape[1]
cvNet.setInput(cv2.dnn.blobFromImage(img, 1.0/127.5, (300, 300), (127.5, 127.5, 127.5), swapRB=True, crop=False))
cvOut = cv2Net.forward()
for detection in cv2Out[0,0,:,:]:
score = float(detection[2])
if score > 0.3:
left = detection[3] * cols
top = detection[4] * rows
right = detection[5] * cols
bottom = detection[6] * rows
cv2.rectangle(img, (int(left), int(top)), (int(right), int(bottom)), (23, 230, 210), thickness=2)
cv2.imshow('img', img)
if cv2.waitKey(1) ==27:
exit(0)
根据我的研究,我认为我必须优化推理图。我找不到任何有关此操作方法的文档。
如果有人能指出我正确的方向,将不胜感激。