# Error loading maskrcnn in opencv dnn

**URL:** <https://forum.opencv.org/t/error-loading-maskrcnn-in-opencv-dnn/3140>\
**Category:** Python\
**Tags:** dnn\
**Created:** [May 5, 2021, 3:16am UTC](https://forum.opencv.org/t/error-loading-maskrcnn-in-opencv-dnn/3140 "2021-05-05T03:16:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffingeorge](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jeffingeorge](https://forum.opencv.org/u/jeffingeorge)\
**Post date:** [May 5, 2021, 3:16am UTC](https://forum.opencv.org/t/error-loading-maskrcnn-in-opencv-dnn/3140/1 "2021-05-05T03:16:33Z")

</div>

Created .pbtxt using this code ([dkurt (Dmitry Kurtaev) · GitHub](https://github.com/dkurt)) tried this solution didn’t worked for me [#16622](https://github.com/opencv/opencv/issues/16622)  
link to pb file [mask\_rcnn\_landing.pb - Google Drive](https://drive.google.com/file/d/18B5_a7uKU6smvg05f6-H-JvsxDZYqGwY/view?usp=sharing)  
pbtxt file  
[model.pbtxt - Google Drive](https://drive.google.com/file/d/1HK86GRMg3LR8N9BPGZL5JyLdxVIxn3N3/view?usp=sharing)

code i tried to generate pbtxt file

```
import tensorflow as tf

with tf.gfile.FastGFile('data/gaze_model.pb', "rb") as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())

    for i in reversed(range(len(graph_def.node))):
        if graph_def.node[i].op == 'Const':
            del graph_def.node[i]

    graph_def.library.Clear()

    tf.train.write_graph(graph_def, "", 'data/gaze_model.pbtxt', as_text=True)

```

error loading to opencv dnn  
and loaded my .pb and generated pbtxt file to opencv dnn ang got error

`Failed to parse GraphDef file: E:/model.pbtxt in function 'cv::dnn::ReadTFNetParamsFromTextFileOrDie'`

```auto

```

---

<div class="post-metadata">

**Author:** ![jeffingeorge](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jeffingeorge](https://forum.opencv.org/u/jeffingeorge)\
**Post date:** [May 5, 2021, 7:55am UTC](https://forum.opencv.org/t/error-loading-maskrcnn-in-opencv-dnn/3140/2 "2021-05-05T07:55:45Z")

</div>

@break a solution that found in wiki but that not working for me please take a look

> **[opencv/opencv](https://github.com/opencv/opencv/wiki/TensorFlow-text-graphs)**
>
> TensorFlow-text-graphs

[Unable to create pbtxt for custom architecture · Issue #16622 · opencv/opencv · GitHub](https://github.com/opencv/opencv/issues/16622)"

something like this

> <https://github.com/opencv/opencv/issues/13050>
>
> \*\*System information (version)\*\*
> OpenCV =\> 3.4.3.18
> Operating System / Platfo…rm =\> Windows 10 64 Bit
> TensorFlow=\> 1.11.0
> \*\*Detailed description\*\*
> I trained a faster\_rcnn\_resnet50 model with 1 class (using the faster\_rcnn\_resnet50\_coco.config) and when I tried to load the network using \`readnetfromtensorflow\`, I got the following error: 
> 
> \> cv2.error: OpenCV(3.4.3) C:\\projects\\opencv-python\\opencv\\modules\\dnn\\src\\tensorflow\\tf\_importer.cpp:495: error: (-2:Unspecified error) Input layer not found: CropAndResize/Reshape/shape in function 'cv::dnn::experimental\_dnn\_34\_v7::\`anonymous-namespace'::TFImporter::connect'
> 
> \[My pbtxt file\](https://github.com/opencv/opencv/files/2551994/frozen\_inference\_graph.zip)
> \[My pb file\](https://drive.google.com/file/d/1YZ5m2fQOJKNtLl\_QdSwJzRAJGB1Gb7zf/view?usp=sharing)
> 
> 
> 
> I generated the pbtxt file through \`tf\_text\_graph\_faster\_rcnn.py\` and also tried generating one after \`optimize\_for\_inference.py\`, but none of them worked out. Need help to fix this! Thanks in advance.
