Is it possible to make the output of all_class_non_max_suppression static shape?

I want to compile an ONNX model with a NonMaxSuppression layer in TVM. To compile this model without using relay VM, I need to make all layers static shape. By setting freeze_params=True, all layers except vision.all_class_non_max_suppression() becomes static shape.

relay.frontend.from_onnx converts ONNX::NonMaxSuppression layer to tvm.relay.vision.all_class_non_max_suppression.

Currently, the output of vision.all_class_non_max_suppression is in dynamic shape because the number of bboxes is determined dynamically.

In vision.non_max_suppression, the output can be made static shape by setting return_indices=False. Similarly, is it possible to extend the implementation of all_class_non_max_suppression to make the output static shape?

More precisely, the question is whether it is possible to make the output of strided_slice inserted after vision.all_class_non_max_suppression() a static shape when ONNX NonMaxSuppression is converted to relayIR.

Hi @lp6m, did you found a solution for this issue? I am facing exactly the same problem trying to use an ONNX model!

No, NMS op in ONNX returns dynamic shape, so we can’t simply drop strided_slice there. The output of all_class_non_max_suppression itself is of static shape.

I was looking to make it a static shape because I thought that was causing my relay.build to break, but after hardcoding the stride in order to get rid of the dynamic stride op, I was still having the issue, so I guess I am still having another problem. I will create a new post with that problem.

oh yes, for models containing dynamic shape, you cannot use relay.build. You need to use the VM compiler and runtime. See https://github.com/apache/tvm/blob/main/gallery/how_to/deploy_models/deploy_object_detection_pytorch.py#L130-L139