Editing input layer of opencv dnn Net

asked 2019-01-27 03:19:04 -0500

updated 2019-01-27 05:01:42 -0500

berak gravatar image

I'm using tensorflow model in opencv using cv.dnn.readNetFromTensorflow. The problem i'm facing is that, i have to set input blobs of variable sizes. But opencv dnn module requires fixed size of input blobs. Please guide me, Is it possible to edit input layer of Net object at run time.

Thanks in Advance.

edit retag flag offensive close merge delete


i have to set input blobs of variable sizes

why is that so ? please explain.

berak gravatar imageberak ( 2019-01-27 03:38:33 -0500 )edit

actually i'm detecting vehicles, in every frame i have to go through two phases, in first phase i down sample the frame to 320x180 to detect near vehicles and in 2nd phase i'm using high resolution cropped frame to detect far away vehicles in a specific region.

abubakarazeem11 gravatar imageabubakarazeem11 ( 2019-01-27 03:55:36 -0500 )edit

2nd phase i'm using high resolution cropped frame to detect far away vehicles in a specific region.

that probably happens at a fixed resolution, too, or no ?

we still don't know, what you're doing, what kind of tensorflow model you use, etc.

berak gravatar imageberak ( 2019-01-27 04:14:24 -0500 )edit

i'm using ssd_mobilenetv2 model. When using fixed size no problem occurs.But as the input blob size changes, predicted bounding boxes are no more accurate.

abubakarazeem11 gravatar imageabubakarazeem11 ( 2019-01-27 04:26:04 -0500 )edit

what i'm doing now is just initialize two separate models, and they are working at fixed input sizes =P

abubakarazeem11 gravatar imageabubakarazeem11 ( 2019-01-27 04:28:17 -0500 )edit

so, if your question was: can i use a single ssd network, and "switch" the input resolution for the 2nd pass, then the answer is: NO. you need 2 seperate models. (and both of them with a "fixed" resolution)

berak gravatar imageberak ( 2019-01-27 04:59:13 -0500 )edit

As @berak said, it's the best choice for now to use two separate networks for different fixed input resolutions. The thing is that changing input shape makes OpenCV reallocates all the internal buffers for a network and reinitialize acceleration backends, if used.

dkurt gravatar imagedkurt ( 2019-01-27 05:22:27 -0500 )edit

Thanks for guiding me. Now i have a reason to use two models. =P

abubakarazeem11 gravatar imageabubakarazeem11 ( 2019-01-27 07:15:49 -0500 )edit