Objects detected as multiple dots while using custom tensorflow model in OpenCV dnn [closed]

asked 2018-02-23 23:33:15 -0600

krishnapra gravatar image

updated 2018-02-24 10:19:40 -0600

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=1YgS...

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

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by krishnapra
close date 2018-03-03 03:26:52.747076

Comments

1

@krishnapra, Please try to run a script tf_text_graph_ssd.pyas described in wiki page https://github.com/opencv/opencv/wiki... to get a text graph. Then pass it as a second argument of readNetFromTensorflow. The first argument will be frozen_inference_graph.pb.

dkurt gravatar imagedkurt ( 2018-02-24 13:16:14 -0600 )edit
1

@dkurt I couldn't get desired result when used text graph generated from tf_text_graph_ssd.py. Result was having no bounding boxes at detections, not even dots. I am not sure why this is happening

I tried replacing prior_box_layer.cpp & tf_importer.cpp in my latest opencv 3.4.0 folder with files at https://github.com/opencv/opencv/pull... and re-compiled opencv. Now i am able to get proper bounding boxes for the code mentioned in my post.

krishnapra gravatar imagekrishnapra ( 2018-02-25 10:57:00 -0600 )edit

@krishnapra I encountered the similar question

I think there are bugs in tf_text_graph_ssd.py

seefun gravatar imageseefun ( 2018-03-15 03:59:45 -0600 )edit