Repository: opencv
Issue: Any plans to officially support the 'NonMaxSuppression' operator from ONNX?
Labels: feature,category: dnn,category: dnn (onnx)

<!--
If you have a question rather than reporting a bug please go to https://forum.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
<!-- Example
- OpenCV => 4.2
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2017
-->

- OpenCV => 4.5.1
- Operating System / Platform => Ubuntu 18.04/20.04
- Compiler => gcc 7.5.0 for Ubuntu 18.04 / gcc 9.3.0 for Ubuntu 20.04

##### Detailed description

<!-- your description -->
ONNX has a built-in node for `NonMaxSuppression` since version>=10, and PyTorch also has `torchvision.ops.nms` since version>=1.2. What I want to say is that it is very natural for PyTorch models to use `torchvision.ops.nms` in their forward test stage if they want to put every operation in a single model (ONNX). And of course, PyTorch has already supported to export an ONNX model with `torchvision.ops.nms`. However, I both checked OpenCV's [wiki](https://github.com/opencv/opencv/wiki/Deep-Learning-in-OpenCV) and the `onnx_importer.cpp`, neither of them showed the support for the 'NonMaxSuppression' op in the current version of OpenCV DNN.

I also learned from https://github.com/amdegroot/ssd.pytorch/pull/462 that the NMS is implemented inside the 'DetectionOutput' node, which is a custom operator from SSD. However, this is not adequate since 'DetectionOutput' has strict requirements with the input. What about a multi-tasking model (face detection + landmark detection)? The node can only work with bboxes but not the landmarks. And also the example to build the node from PyTorch is too complicated without clear documentations, and it seems to only work with a specific version of PyTorch. At least I failed with the later version of PyTorch (1.7.0).

An implementation of 'NonMaxSuppression' node can solve all the above questions. So, any plans to officially support the 'NonMaxSuppression' operator from ONNX? I can make a PR for this if this is not coming in near future.

##### Steps to reproduce

<!-- to add code example fence it with triple backticks and optional file extension
    ```.cpp
    // C++ code example
    ```
 or attach as .txt or .zip file
-->
Any ONNX models with a 'NonMaxSuppression' node. I can share my ONNX model if you don't have one.

##### Issue submission checklist

 - [ ] I report the issue, it's not a question
   <!--
   OpenCV team works with forum.opencv.org, Stack Overflow and other communities
   to discuss problems. Tickets with question without real issue statement will be
   closed.
   -->
 - [x] I checked the problem with documentation, FAQ, open issues,
       forum.opencv.org, Stack Overflow, etc and have not found solution
   <!--
   Places to check:
   * OpenCV documentation: https://docs.opencv.org
   * FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://forum.opencv.org
   * OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
   -->
 - [x] I updated to latest OpenCV version and the issue is still there
   <!--
   master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
   OpenCV team supports only latest release for each branch.
   The ticket is closed, if the problem is not reproduced with modern version.
   -->
 - [x] There is reproducer code and related data files: videos, images, onnx, etc
   <!--
   The best reproducer -- test case for OpenCV that we can add to the library.
   Recommendations for media files and binary files:
   * Try to reproduce the issue with images and videos in opencv_extra repository
     to reduce attachment size
   * Use PNG for images, if you report some CV related bug, but not image reader
     issue
   * Attach the image as archive to the ticket, if you report some reader issue.
     Image hosting services compress images and it breaks the repro code.
   * Provide ONNX file for some public model or ONNX file with with random weights,
     if you report ONNX parsing or handling issue. Architecture details diagram
     from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
   -->