Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Tensorflow Custom Model in OpenCV issues while trying to implementing the solution for mutiplebox anchors

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

contents of my project

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

Tensorflow Custom Model in OpenCV issues while trying to implementing the solution for mutiplebox anchors

I use am using Ubuntu 16.04, built Opencv 3.4, Windows 7 64bit, Visual Studio 2015.

Initially i faced issue of multiple boxes for running custom model trained 3.4.0 from source using master for python 2.7 and 3.5 today (expecting the PR's pushed for tensorflow API using DNN in opencv. After going through solution given by dkurt. multibox anchors dnn issues)

I tried to replicate same frozen_inference_graph.pb & textgraph

contents of my project

On running the sample provided as project.py.

Note: I have modified prior_box_layer.cpp and tf_importer.cpp as suggested in PR#10676project.py

import numpy as np
import cv2 as cv
cvNet = cv.dnn.readNetFromTensorflow('hat_model/frozen_inference_graph.pb', cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'ssd_mobilenet_v1_coco_hat.pbtxt')
img = cv.imread('/home/dkurtaev/Pictures/image5.jpg')
cv.imread('image4.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
cv.waitKey(0)

I got below error. I went through answer suggested to remove assertion. May i know how to remove My files of 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 neededshared here:

https://drive.google.com/open?id=1YgSMBq8vZ5jIoPz8T_CbZIXRYWOfbgRX

Output is with detections having couple of random green color dots as below, instead of rectangular bounding boxes

image description

Any fix for this would be very much helpful

Tensorflow Custom Model in OpenCV issues while trying to implementing the solution for mutiplebox anchors

I am using Ubuntu 16.04, built Opencv 3.4.0 from source using master for python 2.7 and 3.5 today (expecting the PR's pushed for tensorflow multibox anchors dnn issues)

I tried to replicate frozen_inference_graph.pb & textgraph

On running the sample provided as project.py

import numpy as np
import cv2 as cv
cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'ssd_mobilenet_v1_coco_hat.pbtxt')
img = cv.imread('image4.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(0)

My tf_importer.cpp and prior_box_layer.cpp files of this OpenCV master sourceare shared here:

https://drive.google.com/open?id=1YgSMBq8vZ5jIoPz8T_CbZIXRYWOfbgRX

Output is with detections having couple of random green color dots as below, instead of rectangular bounding boxes

image description

Any fix for this would be very much helpful

Tensorflow Custom Model in OpenCV issues while trying to implementing the solution for mutiplebox anchors

I am using Ubuntu 16.04, built Opencv 3.4.0 from source using master for python 2.7 and 3.5 today (expecting the PR's pushed for tensorflow multibox anchors dnn issues)

I tried to replicate frozen_inference_graph.pb & textgraph

On running the sample provided as project.py

import numpy as np
import cv2 as cv
cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'ssd_mobilenet_v1_coco_hat.pbtxt')
img = cv.imread('image4.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(0)

tf_importer.cpp and prior_box_layer.cpp files of OpenCV master sourceare shared here:

https://drive.google.com/open?id=1YgSMBq8vZ5jIoPz8T_CbZIXRYWOfbgRX

Output is with detections having couple of random green color dots as below, instead of rectangular bounding boxes

image description

Any fix for this would be very much helpful