ultralytics / ultralytics

Ultralytics YOLO11 🚀
https://docs.ultralytics.com
GNU Affero General Public License v3.0
32.15k stars 6.17k forks source link

export YOLO11 onnx with NMS #16732

Open Peterande opened 1 month ago

Peterande commented 1 month ago

Search before asking

Question

I used the following code to export my model with ONNX and enabled NMS:

path = model.export(format="onnx", nms=True)

However, the exported ONNX model doesn't seem to include NMS. Could you please let me know how to properly add NMS to the exported ONNX model? Additionally, what are the confidence threshold and IoU threshold values used for NMS in the official reported mAP?

Additional

No response

UltralyticsAssistant commented 1 month ago

👋 Hello @Peterande, thank you for reaching out! We appreciate your interest in Ultralytics 🚀. This is an automated response, but rest assured, an Ultralytics engineer will assist you soon.

In the meantime, I recommend checking out our Docs for guidance on exporting models and integrating NMS (Non-Maximum Suppression).

To help us better understand the issue, could you provide a minimum reproducible example? This will aid in debugging.

For any further queries or detailed discussions, you can join our community:

Upgrade

Make sure to upgrade to the latest ultralytics package in a Python>=3.8 environment with PyTorch>=1.8 using:

pip install -U ultralytics

Environments

You can execute YOLO in various environments with dependencies preinstalled:

Status

Ultralytics CI

If you see a green badge, all Ultralytics CI tests are passing. These tests ensure correct functionality across various platforms.

Stay tuned, and thank you for your patience! 😊

Y-T-G commented 1 month ago

Additionally, what are the confidence threshold and IoU threshold values used for NMS in the official reported mAP?

IoU threshold is 0.6. During mAP calculation, a very low confidence threshold is applied (0.001) due to how mAP is calculated.

You can check the docs for default arguments used: https://docs.ultralytics.com/modes/val/#arguments-for-yolo-model-validation

Skillnoob commented 1 month ago

If you read the docs, it says that the nms argument is only availabe for coreml. https://docs.ultralytics.com/modes/export/#export-formats

Peterande commented 1 month ago

Thank you for your quick reply.

glenn-jocher commented 1 month ago

You're welcome! If you have any more questions, feel free to ask.

YuriGao commented 2 weeks ago

@glenn-jocher Hello, glenn. I still wonder why we coundn't export format ONNX with NMS suppot? According to ONNX Opset 11, there is NonMaxSuppression Op support. Wish for your reply.

Skillnoob commented 2 weeks ago

Ultralytics does not have built in support for adding nms to the onnx models when exporting. You can open a feature request issue and continue from there.

Peterande commented 2 weeks ago

@glenn-jocher Hello, glenn. I still wonder why we coundn't export format ONNX with NMS suppot? According to ONNX Opset 11, there is NonMaxSuppression Op support. Wish for your reply.

Try https://github.com/Peterande/D-FINE/blob/master/tools/deployment/export_yolo_w_nms

glenn-jocher commented 2 weeks ago

@Peterande thank you for the suggestion. We currently don't support exporting ONNX with NMS directly, but you can explore custom solutions like the one you mentioned.

Egorundel commented 2 weeks ago

@glenn-jocher Hello, glenn. I still wonder why we coundn't export format ONNX with NMS suppot? According to ONNX Opset 11, there is NonMaxSuppression Op support. Wish for your reply.

Try https://github.com/Peterande/D-FINE/blob/master/tools/deployment/export_yolo_w_nms

Has anyone checked? Does it work?

glenn-jocher commented 2 weeks ago

@Egorundel i recommend testing the solution in your environment to verify its compatibility. If you encounter issues, feel free to ask for further assistance.