# Problems importing TensorFlow Object Detection Models into OpenCV DNN C++

**URL:** <https://forum.opencv.org/t/problems-importing-tensorflow-object-detection-models-into-opencv-dnn-c/1838>\
**Category:** C++\
**Tags:** dnn, tensorflow\
**Created:** [February 26, 2021, 3:16pm UTC](https://forum.opencv.org/t/problems-importing-tensorflow-object-detection-models-into-opencv-dnn-c/1838 "2021-02-26T15:16:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joni7373](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joni7373/32/1174_2.png) [@joni7373](https://forum.opencv.org/u/joni7373)\
**Post date:** [February 26, 2021, 3:16pm UTC](https://forum.opencv.org/t/problems-importing-tensorflow-object-detection-models-into-opencv-dnn-c/1838/1 "2021-02-26T15:16:10Z")

</div>

Hello everyone,

I would like to use the **OpenCV DNN** (C++) module to make predictions using a pre-trained TensorFlow 2.x object detection model ( **Mask R-CNN Inception ResNet V2 1024x1024** ). I have already adapted and retrained the model with Python and TesorFlow for my own input images and can also run the inference e.g. on a single test image. So everything seems to be working on the TensorFlow side.

Now I want to port this model to OpenCV and run the inference using the DNN module.  
Since I used TensorFlow 2.x, which no longer supports the “frozen graph format” needed for the DNN module to work, I have to convert Tensorflow’s “saved model format” into the “frozen graph format”.

But now I fail at creating the **“config file”** (often also refered to as **graph.pbtxt** file), which I have to pass to the **readNetFromTensorflow(const String &model, const String &config = String())** method.

The Python script that is supposed to create this file for me ( **tf\_text\_graph\_mask\_rcnn.py** ) fails with the following error message:  
File “tf\_text\_graph\_mask\_rcnn.py”, line 41, in .  
features\_stride = float(config[‘feature\_extractor’][0][‘first\_stage\_features\_stride’][0])  
KeyError: ‘first\_stage\_features\_stride’

Can anyone help me here, has anyone had similar problems ?

Thanks,  
Jonas

---

<div class="post-metadata">

**Author:** ![Alejandro\_Silvestri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/alejandro_silvestri/32/357_2.png) [@Alejandro\_Silvestri](https://forum.opencv.org/u/Alejandro_Silvestri)\
**Post date:** [March 4, 2021, 12:35pm UTC](https://forum.opencv.org/t/problems-importing-tensorflow-object-detection-models-into-opencv-dnn-c/1838/2 "2021-03-04T12:35:59Z")

</div>

Hi @joni7373 ,

I’m new to dnn, but since anyone replied I dare to share my shallow knowledge.

As you already know, readNetFromTensorflow accepts 2 parameters: model (aka weights) and config (aka net). The last one is optional.

I see a lot of examples using this function with one parameter, the model. And that’s possible when the file contains both weights and net, a pretty convenient thing to do as nets are one thousand times smaller than weights.

Did you tried not using a config file? May be you already know this is not possible in you case.

---

<div class="post-metadata">

**Author:** ![joni7373](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joni7373/32/1174_2.png) [@joni7373](https://forum.opencv.org/u/joni7373)\
**Post date:** [March 5, 2021, 6:54am UTC](https://forum.opencv.org/t/problems-importing-tensorflow-object-detection-models-into-opencv-dnn-c/1838/3 "2021-03-05T06:54:50Z")

</div>

Hello,  
thank you for your answer. Actually, I wanted to delete this post because I have explained my problem in more detail in a new post ( [I want to import TensorFlow 2.x - Object Detection - Mask R-CNN Model in OpenCV DNN API](https://forum.opencv.org/t/i-want-to-import-tensorflow-2-x-object-detection-mask-r-cnn-model-in-opencv-dnn-api/1937) ). Unfortunately, I did not find a delete option. Please have a look at my new post. Thank you.
