[ONNX] Ssd-mobilenetv1 fail to build

I don’t know exactly where the error occurred.
More information on github.

Thanks.

The github issues :

It seems that relay.nn.conv2d has not supported dynamic shape in W and H dimension yet. A workaround is to “freeze” the model’s W and H dimension using tools like GitHub - daquexian/onnx-simplifier: Simplify your onnx model, and recompile it.

1 Like

Thank you for your reply, GitHub-daquexian/onnx-simplifier I tried, but still the same error.

Maybe I used the wrong method, the following code:

...
        onnx_model, check = simplify(onnx_model, input_shapes=shape_dict)
        assert check, "Simplified ONNX model could not be validated"

        print(f'Importing graph from ONNX to TVM Relay IR ...')
        mod, params = relay.frontend.from_onnx(onnx_model, shape_dict, freeze_params=True)
        mod = relay.transform.DynamicToStatic()(mod)


        print(f'Compiling graph from Relay IR to {target} ...')
        with tvm.transform.PassContext(opt_level=3):
            vm_exec = relay.vm.compile(mod, target, params=params)
...

But the problem seems to be because Loop is implemented with ‘Let Binding’, but it does not have a good support dynamic shape.

    let %while_loop: fn (int64, int64, bool, int32, Tensor[(?, ?, ?), float32], Tensor[(?, ?), float32], Tensor[(?), int32], Tensor[(?, ?), float32]) -> (int64, int64, bool, int32, Tensor[(?, ?, ?), float32], Tensor[(?, ?), float32], Tensor[(?), int32], Tensor[(?, ?), float32]) = fn (%i__25: int64, %max_count: int64, %cond__27: bool, %Postprocessor/BatchMultiClassNonMaxSuppression/map/while/Identity:0: int32, %sub_graph_ending_node_Identity__21:0: Tensor[(?, ?, ?), float32], %sub_graph_ending_node_Identity__22:0: Tensor[(?, ?), float32], %sub_graph_ending_node_Identity__23:0: Tensor[(?), int32], %sub_graph_ending_node_Identity__24:0: Tensor[(?, ?), float32]) -> (int64, int64, bool, int32, Tensor[(?, ?, ?), float32], Tensor[(?, ?), float32], Tensor[(?), int32], Tensor[(?, ?), float32]) {
...
        %37 = subtract(%36, meta[relay.Constant][5] /* ty=Tensor[(1, 1, 1, 1), float32] */) /* ty=Tensor[(?, ?, ?, ?), float32] */;
        %38 = nn.conv2d(%37, meta[relay.Constant][6] /* ty=Tensor[(32, 3, 3, 3), float32] */, strides=[2, 2], padding=[0, 0, 1, 1], kernel_size=[3, 3]) /* ty=Tensor[(?, 32, ?, ?), float32] */;
...
}

Will relay.transform.DynamicToStatic() help you freeze the shape? I encountered the same error while parsing a frozen ONNX model, some shapes still giving me ? so I need to run relay.transform.DynamicToStatic to make it static.