Error features_stride = float tensorflow model in opencv dnn

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

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

this is actually not from the dnn, but from a tf-based preprocessing script

please check your config file for the missing key first_stage_features_stride

@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'

you’re using the wrong tf version

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

@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
this is the latest file please take a look
opencvdnn - Google Drive
thanks

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))

@berak thanks berak let me check

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

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'