# Error features\_stride = float tensorflow model in opencv dnn

**URL:** <https://forum.opencv.org/t/error-features-stride-float-tensorflow-model-in-opencv-dnn/3319>\
**Category:** Python\
**Tags:** dnn\
**Created:** [May 13, 2021, 9:55am UTC](https://forum.opencv.org/t/error-features-stride-float-tensorflow-model-in-opencv-dnn/3319 "2021-05-13T09:55:33Z")\
**Posts on this page:** 8\
**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 13, 2021, 9:55am UTC](https://forum.opencv.org/t/error-features-stride-float-tensorflow-model-in-opencv-dnn/3319/1 "2021-05-13T09:55:33Z")

</div>

was trying to make pbtxt file using my trained model and config file and got this error using tf\_text\_graph\_mask\_rcnn.py  
opencv version 4.5.2

```auto
Traceback (most recent call last):
  File "E:\mask_rcnn_inception_v2_coco_2018_01_28\opencv\sources\samples\dnn\tf_text_graph_mask_rcnn.py", line 41, in <module>
    features_stride = float(config['feature_extractor'][0]['first_stage_features_stride'][0])
KeyError: 'first_stage_features_stride'

```

files  
[https://drive.google.com/drive/folders/19OEdYZsGu8l41L42BW3ZswISor1RXvRd?usp=sharing](https://drive.google.com/drive/folders/19OEdYZsGu8l41L42BW3ZswISor1RXvRd?usp=sharing)

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [May 13, 2021, 10:51am UTC](https://forum.opencv.org/t/error-features-stride-float-tensorflow-model-in-opencv-dnn/3319/2 "2021-05-13T10:51:54Z")

</div>

this is actually not from the dnn, but from a [tf-based preprocessing script](https://github.com/opencv/opencv/blob/aadbebf9d87535fc5eaa42f8c33911b8e2408410/samples/dnn/tf_text_graph_mask_rcnn.py#L41)

please check your config file for the missing key `first_stage_features_stride`

---

<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 14, 2021, 9:17am UTC](https://forum.opencv.org/t/error-features-stride-float-tensorflow-model-in-opencv-dnn/3319/3 "2021-05-14T09:17:44Z")

</div>

@berak figured out the first stage feature\_stirde and now new error  
T raceback (most recent call last):  
\> File “E:\mask\_rcnn\_inception\_v2\_coco\_2018\_01\_28\opencv\sources\samples\dnn\tf\_text\_graph\_common.py”, line 313, in writeTextGraph

> ```
> cv.dnn.writeTextGraph(modelPath, outputPath)
> cv2.error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\dnn\src\tensorflow\tf_io.cpp:42: error: (-2:Unspecified error) FAILED: ReadProtoFromBinaryFile(param_file, param). Failed to parse GraphDef file: E:\mask_rcnn_inception_v2_coco_2018_01_28\motabiju\saved_model.pb in function 'cv::dnn::ReadTFNetParamsFromBinaryFileOrDie'
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
> File "E:\mask_rcnn_inception_v2_coco_2018_01_28\opencv\sources\samples\dnn\tf_text_graph_mask_rcnn.py", line 53, in <module>
> writeTextGraph(args.input, args.output, ['num_detections', 'detection_scores', 'detection_boxes', 'detection_classes', 'detection_masks'])
> File "E:\mask_rcnn_inception_v2_coco_2018_01_28\opencv\sources\samples\dnn\tf_text_graph_common.py", line 316, in writeTextGraph
> from tensorflow.tools.graph_transforms import TransformGraph
> ModuleNotFoundError: No module named 'tensorflow.tools.graph_transforms'
> 
> ```

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [May 14, 2021, 9:36am UTC](https://forum.opencv.org/t/error-features-stride-float-tensorflow-model-in-opencv-dnn/3319/4 "2021-05-14T09:36:09Z")

</div>

you’re using the wrong tf version

(2.0 is no more grapfdef based (iirc), try something older, like 1.5)

---

<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 14, 2021, 9:52am UTC](https://forum.opencv.org/t/error-features-stride-float-tensorflow-model-in-opencv-dnn/3319/5 "2021-05-14T09:52:32Z")

</div>

@berak sorry berak above link is tf2 this file , today i trained in tf1.15.0 with \* mask\_rcnn\_resnet101\_atrous\_coco\_2018\_01\_28  
found from opencv wiki [Enable Mask-RCNN models with dilated convolutions from TensorFlow by dkurt · Pull Request #13766 · opencv/opencv · GitHub](https://github.com/opencv/opencv/pull/13766)  
this is the latest file please take a look  
[opencvdnn - Google Drive](https://drive.google.com/drive/folders/19OEdYZsGu8l41L42BW3ZswISor1RXvRd)  
thanks

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [May 14, 2021, 10:20am UTC](https://forum.opencv.org/t/error-features-stride-float-tensorflow-model-in-opencv-dnn/3319/6 "2021-05-14T10:20:04Z")

</div>

sorry, but i have no real idea about mask-rnn or tf, but if the model on your ggl drive is only 2mb, it’s probably broken (should be \>500mb, iirc(which is why i never downloaded it))

---

<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 14, 2021, 11:27am UTC](https://forum.opencv.org/t/error-features-stride-float-tensorflow-model-in-opencv-dnn/3319/7 "2021-05-14T11:27:10Z")

</div>

@berak thanks berak let me check

---

<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 15, 2021, 9:19am UTC](https://forum.opencv.org/t/error-features-stride-float-tensorflow-model-in-opencv-dnn/3319/8 "2021-05-15T09:19:24Z")

</div>

@berak can you tell which models that support for opencv dnn? here is the full trace on my error

```auto
Number of classes: 90
Scales: [0.25, 0.5, 1.0, 2.0]
Aspect ratios: [0.5, 1.0, 2.0]
Width stride: 16.000000
Height stride: 16.000000
Features stride: 8.000000
[libprotobuf ERROR C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\3rdparty\protobuf\src\google\protobuf\wire_format_lite.cc:629] String field 'opencv_tensorflow.FunctionDef.Node.ret' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes.
2021-05-15 13:18:22.371302: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-05-15 13:18:22.371450: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "E:\mask_rcnn_inception_v2_coco_2018_01_28\opencv\sources\samples\dnn\tf_text_graph_common.py", line 313, in writeTextGraph
    cv.dnn.writeTextGraph(modelPath, outputPath)
cv2.error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\dnn\src\tensorflow\tf_io.cpp:42: error: (-2:Unspecified error) FAILED: ReadProtoFromBinaryFile(param_file, param). Failed to parse GraphDef file: E:\mask_rcnn_inception_v2_coco_2018_01_28\motabiju\saved_model.pb in function 'cv::dnn::ReadTFNetParamsFromBinaryFileOrDie'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\mask_rcnn_inception_v2_coco_2018_01_28\opencv\sources\samples\dnn\tf_text_graph_mask_rcnn.py", line 53, in <module>
    writeTextGraph(args.input, args.output, ['num_detections', 'detection_scores', 'detection_boxes', 'detection_classes', 'detection_masks'])
  File "E:\mask_rcnn_inception_v2_coco_2018_01_28\opencv\sources\samples\dnn\tf_text_graph_common.py", line 316, in writeTextGraph
    from tensorflow.tools.graph_transforms import TransformGraph
ModuleNotFoundError: No module named 'tensorflow.tools.graph_transforms'

```
