Skip to content

Error of converting Mask RCNN .pb to onnx #767

@chiehpower

Description

@chiehpower

Describe the situation

I wonder to convert .pb model of Mask RCNN which was trained by Keras to .onnx model.

Let me describe my situation. I was trying to do a Mask RCNN sample of TensorRT for python API.
My strategy is to download the pre-trained Keras .h5 model then converting it to .pb format.
Next, I wanna use the tensorflow-onnx to convert the model from .pb to .onnx format.
(Don't worry. Until now, it is irrelevant with the TensorRT part.)

Implement the command

This is my command.

python3 -m tf2onnx.convert --graphdef ./mask_rcnn_coco.pb --output ./mask_rcnn_coco.onnx \
    --fold_const --opset 10 \
    --inputs input_image:0\
    --outputs mrcnn_mask/Sigmoid:0 

Error Message

When I converted the model, I got this error below.

/home/chieh/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/chieh/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
WARNING:tensorflow:From /home/chieh/.local/lib/python3.6/site-packages/tf2onnx/verbose_logging.py:72: The name tf.logging.set_verbosity is deprecated. Please use tf.compat.v1.logging.set_verbosity instead.

2020-01-08 09:04:56,183 - WARNING - From /home/chieh/.local/lib/python3.6/site-packages/tf2onnx/verbose_logging.py:72: The name tf.logging.set_verbosity is deprecated. Please use tf.compat.v1.logging.set_verbosity instead.

2020-01-08 09:04:58.613282: E tensorflow/tools/graph_transforms/transform_graph.cc:332] fold_constants: Ignoring error You must feed a value for placeholder tensor 'input_image_meta' with dtype float and shape [?,93]
         [[{{node input_image_meta}}]]
2020-01-08 09:04:59,893 - INFO - Using tensorflow=1.14.0, onnx=1.6.0, tf2onnx=1.5.3/7b598d
2020-01-08 09:04:59,893 - INFO - Using opset <onnx, 10>
2020-01-08 09:05:10,771 - ERROR - Failed to convert node ROI/Pad
OP=Pad
Name=ROI/Pad
Inputs:
        ROI/GatherV2_3:0=Gather, [-1, 4], 1
        ROI/Pad/paddings_Concat__2376:0=Concat, [2, 2], 6
Outpus:
        ROI/Pad:0=[-1, -1], 1
Traceback (most recent call last):
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/onnx_opset/nn.py", line 401, in version_1
    paddings = np.array(node.inputs[1].get_tensor_value()).transpose().flatten()
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/graph.py", line 256, in get_tensor_value
    raise ValueError("get tensor value: {} must be Const".format(self.name))
ValueError: get tensor value: ROI/Pad/paddings_Concat__2376 must be Const
2020-01-08 09:05:10,779 - ERROR - Tensorflow op [roi_align_classifier/Round: Round] is not supported
2020-01-08 09:05:10,981 - ERROR - Tensorflow op [roi_align_classifier/CropAndResize_3: CropAndResize] is not supported
2020-01-08 09:05:10,989 - ERROR - Tensorflow op [roi_align_classifier/CropAndResize_2: CropAndResize] is not supported
2020-01-08 09:05:10,997 - ERROR - Tensorflow op [roi_align_classifier/CropAndResize_1: CropAndResize] is not supported
2020-01-08 09:05:11,005 - ERROR - Tensorflow op [roi_align_classifier/CropAndResize: CropAndResize] is not supported
2020-01-08 09:05:11,556 - ERROR - Tensorflow op [mrcnn_detection/DenseToDenseSetOperation: DenseToDenseSetOperation] is not supported
2020-01-08 09:05:11,556 - ERROR - Tensorflow op [mrcnn_detection/SparseToDense: SparseToDense] is not supported
2020-01-08 09:05:11,576 - ERROR - Tensorflow op [mrcnn_detection/Unique: Unique] is not supported
2020-01-08 09:05:11,748 - ERROR - Failed to convert node mrcnn_detection/map/while/PadV2
OP=Pad
Name=mrcnn_detection/map/while/PadV2
Inputs:
        mrcnn_detection/map/while/GatherV2_3:0=Gather, [-1], 7
        mrcnn_detection/map/while/PadV2/paddings_Concat__3110:0=Concat, [1, 2], 6
        mrcnn_detection/map/while/PadV2/constant_values:0=Const, [], 7
Outpus:
        mrcnn_detection/map/while/PadV2:0=[-1], 7
Traceback (most recent call last):
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/onnx_opset/nn.py", line 401, in version_1
    paddings = np.array(node.inputs[1].get_tensor_value()).transpose().flatten()
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/graph.py", line 256, in get_tensor_value
    raise ValueError("get tensor value: {} must be Const".format(self.name))
ValueError: get tensor value: mrcnn_detection/map/while/PadV2/paddings_Concat__3110 must be Const
2020-01-08 09:05:11,775 - ERROR - Tensorflow op [mrcnn_detection/DenseToDenseSetOperation_1: DenseToDenseSetOperation] is not supported
2020-01-08 09:05:11,775 - ERROR - Tensorflow op [mrcnn_detection/SparseToDense_1: SparseToDense] is not supported
2020-01-08 09:05:11,828 - ERROR - Failed to convert node mrcnn_detection/strided_slice_29
OP=StridedSlice
Name=mrcnn_detection/strided_slice_29
Inputs:
        mrcnn_detection/GatherV2_8:0=Gather, [-1], 1
        mrcnn_detection/strided_slice_29/stack:0=Const, [2], 6
        mrcnn_detection/strided_slice_29/stack_1:0=Const, [2], 6
        mrcnn_detection/strided_slice_29/stack_2:0=Const, [2], 6
Outpus:
        mrcnn_detection/strided_slice_29:0=[-1, 1], 1
Traceback (most recent call last):
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/onnx_opset/tensor.py", line 686, in version_10
    cls.version_1(ctx, node, **kwargs)
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/onnx_opset/tensor.py", line 569, in version_1
    raise ValueError("StridedSlice: attribute " + attr_name + " not supported")
ValueError: StridedSlice: attribute new_axis_mask not supported
2020-01-08 09:05:11,828 - ERROR - Failed to convert node mrcnn_detection/strided_slice_28
OP=StridedSlice
Name=mrcnn_detection/strided_slice_28
Inputs:
        mrcnn_detection/ToFloat:0=Cast, [-1], 1
        mrcnn_detection/strided_slice_28/stack:0=Const, [2], 6
        mrcnn_detection/strided_slice_28/stack_1:0=Const, [2], 6
        mrcnn_detection/strided_slice_28/stack_2:0=Const, [2], 6
Outpus:
        mrcnn_detection/strided_slice_28:0=[-1, 1], 1
Traceback (most recent call last):
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/onnx_opset/tensor.py", line 686, in version_10
    cls.version_1(ctx, node, **kwargs)
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/onnx_opset/tensor.py", line 569, in version_1
    raise ValueError("StridedSlice: attribute " + attr_name + " not supported")
ValueError: StridedSlice: attribute new_axis_mask not supported
2020-01-08 09:05:11,873 - ERROR - Failed to convert node mrcnn_detection/Pad
OP=Pad
Name=mrcnn_detection/Pad
Inputs:
        mrcnn_detection/concat_1:0=Concat, [-1, 6], 1
        mrcnn_detection/Pad/paddings_Concat__3161:0=Concat, [2, 2], 6
Outpus:
        mrcnn_detection/Pad:0=[-1, -1], 1
Traceback (most recent call last):
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/onnx_opset/nn.py", line 401, in version_1
    paddings = np.array(node.inputs[1].get_tensor_value()).transpose().flatten()
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/graph.py", line 256, in get_tensor_value
    raise ValueError("get tensor value: {} must be Const".format(self.name))
ValueError: get tensor value: mrcnn_detection/Pad/paddings_Concat__3161 must be Const
2020-01-08 09:05:11,881 - ERROR - Tensorflow op [roi_align_mask/Round: Round] is not supported
2020-01-08 09:05:12,085 - ERROR - Tensorflow op [roi_align_mask/CropAndResize_3: CropAndResize] is not supported
2020-01-08 09:05:12,093 - ERROR - Tensorflow op [roi_align_mask/CropAndResize_2: CropAndResize] is not supported
2020-01-08 09:05:12,100 - ERROR - Tensorflow op [roi_align_mask/CropAndResize_1: CropAndResize] is not supported
2020-01-08 09:05:12,108 - ERROR - Tensorflow op [roi_align_mask/CropAndResize: CropAndResize] is not supported
2020-01-08 09:05:12,350 - ERROR - Unsupported ops: Counter({'CropAndResize': 8, 'Round': 2, 'DenseToDenseSetOperation': 2, 'SparseToDense': 2, 'Unique': 1})
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/convert.py", line 161, in <module>
    main()
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/convert.py", line 145, in main
    inputs_as_nchw=args.inputs_as_nchw)
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/tfonnx.py", line 575, in process_tf_graph
    raise exceptions[0]
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/onnx_opset/nn.py", line 401, in version_1
    paddings = np.array(node.inputs[1].get_tensor_value()).transpose().flatten()
  File "/home/chieh/.local/lib/python3.6/site-packages/tf2onnx/graph.py", line 256, in get_tensor_value
    raise ValueError("get tensor value: {} must be Const".format(self.name))
ValueError: get tensor value: ROI/Pad/paddings_Concat__2376 must be Const

System information

  • Ubuntu 18.04
  • Tensorflow Version: 1.14
  • Python version: 3.6
  • Onnx version: 1.16
  • Keras version: 2.3.1

To Reproduce

  1. Download the file from github
    https://github.com/NVIDIA/TensorRT/tree/master/samples/opensource/sampleUffMaskRCNN/converted/mrcnn_to_trt_single.py
  2. Follow the step 6 of prerequisites to get the model.
    wget https://github.com/matterport/Mask_RCNN/releases/download/v2.0/mask_rcnn_coco.h5
  3. Modify the code of mrcnn_to_trt_single.py. We just need to get rid of this function uff.from_tensorflow_frozen_model from line 150 to line 160. In addition, modify the output .pb path, here.
    Then we can implement this command.
python3 mrcnn_to_trt_single.py -w ./mask_rcnn_coco.h5 -o ./mask_rcnn_coco.uff

Dont worry. It just requests users to provide an output .uff path, but it will not be used in the end.
We can get a .pb file.

BTW if you didn't have the uff package, please remove it. here

  1. Type this command on our terminal line.
python3 -m tf2onnx.convert --graphdef ./mask_rcnn_coco.pb --output ./mask_rcnn_coco.onnx \
    --fold_const --opset 10 \
    --inputs input_image:0\
    --outputs mrcnn_mask/Sigmoid:0 

Be careful of your .pb path.

Here, I was not completely sure whether it was caused by the input and output nodes.
However, it looks like an operation problem from error messages.

Expected behavior

Successfully get the onnx model of Mask RCNN.

Is there any idea about this situation?
Your comments and suggestions are welcome!

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions