Ask Your Question
1

OpenCV dnn: Precision Loss when using TensorFlow Object Detection model

asked 2018-03-12 08:19:30 -0600

seefun gravatar image

updated 2018-03-13 02:51:52 -0600

I using the code from this: https://github.com/opencv/opencv/wiki...

I use the same network and model to run the SSD-Mobilenet detection. But when I run the network in opencv, the result is obviously worse than the same model runing in Tensorflow.

Why? And what can I do to solve it?

the output in opencv3.4.1:(threshould0.5 nms0.5)

image description

the output in tensorflow1.4:(the same nms and threshould config)

image description

edit retag flag offensive close merge delete

Comments

@seefun, please specify a model did you use. Also the version of OpenCV. Attached images will also be more useful.

dkurt gravatar imagedkurt ( 2018-03-13 02:40:10 -0600 )edit

@dkurt ,my OpenCV version is 3.4.1 use the tensorflow object detection api config file in this: https://github.com/tensorflow/models/...

seefun gravatar imageseefun ( 2018-03-13 02:45:05 -0600 )edit

@seefun, is it possible to share a frozen graph to reproduce results?

dkurt gravatar imagedkurt ( 2018-03-13 03:02:45 -0600 )edit

@dkurt can you give me your e-mail. I'll send it to you. Thanks a lot

seefun gravatar imageseefun ( 2018-03-13 03:09:31 -0600 )edit

@seefun, please check it in profile, http://answers.opencv.org/users/13258... . BTW, have you tested MobileNet-SSD models using your code and script to generate .pbtxt file rather using attached ones? Maybe it's not necessary to share the model and we can find a mistake in application code. Did you use exactly the same python code as added in wiki page?

dkurt gravatar imagedkurt ( 2018-03-13 04:19:40 -0600 )edit

@dkurt I use the latest script in this wiki pages to creat .pbtxt file, and try these two menthod from trouble shooting, but I get the error:

error: (-215) !_aspectRatios.empty(), _minSize > 0 in function cv::dnn::PriorBoxLayerImpl::PriorBoxLayerImpl

my graph.pb is here https://jbox.sjtu.edu.cn/l/71KeO6

seefun gravatar imageseefun ( 2018-03-13 09:32:51 -0600 )edit

@seefun, May I ask you to check OpenCV source code state? Do you really use OpenCV 3.4.1? Please print OpenCV version using CV_VERSION in C++ or cv2.__version__ in python.

dkurt gravatar imagedkurt ( 2018-03-13 09:43:42 -0600 )edit

@dkurt Ohh,I use the wrong version of OpenCV. But when I use the latest OpenCV3.4.1, the result from Tensorflow and OpenCV are still different. The bandboxs output from OpenCV are sometimes too small or too big . Whether the output size of bandbox are fixed? or opencv delete the box regression operation?

seefun gravatar imageseefun ( 2018-03-14 06:39:12 -0600 )edit

@seefun, Could you please check a link to the model because I couldn't download it nigher yesterday nor now. If you cannot share a model please try to generate .pbtxt file for a public MobileNet-SSD model and test it too. Otherwise it's hard to debug remotely.

dkurt gravatar imagedkurt ( 2018-03-14 07:13:46 -0600 )edit

1 answer

Sort by » oldest newest most voted
2

answered 2018-03-14 09:08:17 -0600

dkurt gravatar image

@seefun, thanks for your help! I could reproduce a bug. I guess you saw something like this: image description

It turned out that you need to change only two lines in the generated .pbtxt to make it work:

at node with a name PriorBox_0 in the width field from

    float_val: 3.0
    float_val: 8.4852809906
    float_val: 4.24264097214

to

    float_val: 30
    float_val: 8.4852809906
    float_val: 4.24264097214

and in the same node but in height field:

from

    float_val: 3.0
    float_val: 4.24264097214
    float_val: 8.4852809906

to

    float_val: 30
    float_val: 4.24264097214
    float_val: 8.4852809906

image description

edit flag offensive delete link more

Comments

yeah, I get the result of this. Thanks for your help!I solve the problem.

seefun gravatar imageseefun ( 2018-03-14 09:18:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-12 08:19:30 -0600

Seen: 1,195 times

Last updated: Mar 14 '18