I use Opencv 3.4, Windows 7 64bit, Visual Studio 2015.
Initially i faced issue of multiple boxes for running custom model trained using tensorflow API using DNN in opencv. After going through solution given by dkurt. I tried to replicate same frozen_inference_graph.pb & textgraph
On running the sample provided as project.py.
Note: I have modified prior_box_layer.cpp and tf_importer.cpp as suggested in PR#10676
import numpy as np
import cv2 as cv
cvNet = cv.dnn.readNetFromTensorflow('hat_model/frozen_inference_graph.pb', 'ssd_mobilenet_v1_coco_hat.pbtxt')
img = cv.imread('/home/dkurtaev/Pictures/image5.jpg')
cvNet.setInput(cv.dnn.blobFromImage(img, 1.0/127.5, (300, 300), (127.5, 127.5, 127.5), swapRB=True, crop=False))
cvOut = cvNet.forward()
for detection in cvOut[0,0,:,:]:
score = float(detection[2])
if score > 0.5:
left = detection[3] * img.shape[1]
top = detection[4] * img.shape[0]
right = detection[5] * img.shape[1]
bottom = detection[6] * img.shape[0]
cv.rectangle(img, (int(left), int(top)), (int(right), int(bottom)), (0, 255, 0))
cv.imshow('img', img)
cv.waitKey
I got below error. I went through answer suggested to remove assertion. May i know how to remove this ? or any alternate solution?
C:\dl>python project.py
[ INFO:0] Initialize OpenCL runtime...
OpenCV Error: Assertion failed (!_aspectRatios.empty(), _minSize > 0) in cv::dnn
::PriorBoxLayerImpl::PriorBoxLayerImpl, file C:\build\master_winpack-bindings-wi
n64-vc14-static\opencv\modules\dnn\src\layers\prior_box_layer.cpp, line 207
Traceback (most recent call last):
File "project.py", line 8, in <module>
cvOut = cvNet.forward()
cv2.error: C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\dnn
\src\layers\prior_box_layer.cpp:207: error: (-215) !_aspectRatios.empty(), _minS
ize > 0 in function cv::dnn::PriorBoxLayerImpl::PriorBoxLayerImpl
Let me know if any further details are needed