Convert Pytorch to ONNX then to Openvino IR

kenfack: <p>I have trained a mask rcnn model using transfers learning in PyTorch on the custom dataset.</p>
<pre><code class="lang-auto">num_classes = 4
model = models.detection.maskrcnn_resnet50_fpn(pretrained=True)
in_features = model.roi_heads.box_predictor.cls_score.in_features
model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
in_features_mask = model.roi_heads.mask_predictor.conv5_mask.in_channels
hidden_layer = 256
model.roi_heads.mask_predictor = MaskRCNNPredictor(in_features_mask,hidden_layer,num_classes)
</code></pre>
<p>Now I need to covert the resulted model into ONNX then from ONNX convert to Openvino IR. So I converted the model from torch to ONNX</p>
<pre><code class="lang-auto"># Export the model to ONNX model
batch_size = 1
x = torch.randn(1,3,1080,1080)
model.eval()
torch_out = model(x)
torch.onnx.export(
    model,
    x,
    "cocoa_diseasis_model.onnx",
    export_params=True,
    opset_version=11,
    verbose=False,
    do_constant_folding=True,
    input_names = ['input'],
    output_names = ['output'],
    dynamic_axes={'input' : {0 : 'batch_size'}, 'output' : {0 : 'batch_size'}}
)
</code></pre>
<p>but trying to get the IR of that model generates the following error.</p>
<pre><code class="lang-auto">py ./mo_onnx.py --input_model input_model\model.onnx --transformations_config ./extensions/front/onnx/mask_rcnn.json
</code></pre>
<pre><code class="lang-auto">[ ERROR ]  -------------------------------------------------
[ ERROR ]  ----------------- INTERNAL ERROR ----------------
[ ERROR ]  Unexpected exception happened.
[ ERROR ]  Please contact Model Optimizer developers and forward the following information:
[ ERROR ]  Exception occurred during running replacer "ONNXMaskRCNNReplacement (&lt;class 'extensions.front.onnx.mask_rcnn_conversion.ONNXMaskRCNNTransformation'&gt;)": Attempt to access node 2751 that not in graph
[ ERROR ]  Traceback (most recent call last):
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\utils\class_registration.py", line 278, in apply_transform
    for_graph_and_each_sub_graph_recursively(graph, replacer.find_and_replace_pattern)
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\middle\pattern_match.py", line 46, in for_graph_and_each_sub_graph_recursively
    func(graph)
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\front\tf\replacement.py", line 36, in find_and_replace_pattern
    self.transform_graph(graph, desc._replacement_desc['custom_attributes'])
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\extensions\front\onnx\mask_rcnn_conversion.py", line 38, in transform_graph
    insert_ExperimentalDetectronROIFeatureExtractor2(graph, replacement_descriptions)
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\extensions\front\onnx\mask_rcnn_conversion.py", line 103, in insert_ExperimentalDetectronROIFeatureExtractor2
    old_output_node = Node(graph, replacement_descriptions['ROIFeatureExtractor2_output'])
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\graph\graph.py", line 25, in __init__
    assert node in graph, "Attempt to access node {} that not in graph".format(node)
AssertionError: Attempt to access node 2751 that not in graph

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\main.py", line 394, in main
    ret_code = driver(argv)
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\main.py", line 356, in driver
    ret_res = emit_ir(prepare_ir(argv), argv)
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\main.py", line 252, in prepare_ir
    graph = unified_pipeline(argv)
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\pipeline\unified.py", line 13, in unified_pipeline
    class_registration.apply_replacements(graph, [
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\utils\class_registration.py", line 328, in apply_replacements
    apply_replacements_list(graph, replacers_order)
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\utils\class_registration.py", line 314, in apply_replacements_list
    apply_transform(
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\utils\logger.py", line 111, in wrapper
    function(*args, **kwargs)
  File "C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\model_optimizer\mo\utils\class_registration.py", line 302, in apply_transform
    raise Exception('Exception occurred during running replacer "{} ({})": {}'.format(
Exception: Exception occurred during running replacer "ONNXMaskRCNNReplacement (&lt;class 'extensions.front.onnx.mask_rcnn_conversion.ONNXMaskRCNNTransformation'&gt;)": Attempt to access node 2751 that not in graph

[ ERROR ]  ---------------- END OF BUG REPORT --------------
[ ERROR ]  -------------------------------------------------
</code></pre>

camvet: <p>Did you ever figure this out?  I’m in exactly the same situation with the same error message…</p>