Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add NMS to last layer? #1726

Closed
rsundar96 opened this issue Mar 29, 2021 · 9 comments
Closed

How to add NMS to last layer? #1726

rsundar96 opened this issue Mar 29, 2021 · 9 comments
Labels
question Further information is requested

Comments

@rsundar96
Copy link

I want to add the NMS as part of the last layer and can see under models/yolo.py that the function nms is present (Line 173, models/yolo.py). How do I add this to my model? (Haven't made any changes to the model architecture present in the repo)

Screenshot 2021-03-29 at 20 58 35

@rsundar96 rsundar96 added the question Further information is requested label Mar 29, 2021
@github-actions
Copy link

github-actions bot commented Mar 29, 2021

👋 Hello @rsundar96, thank you for your interest in 🚀 YOLOv3! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

Environments

YOLOv3 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv3 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv3 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

glenn-jocher commented Mar 29, 2021

@rsundar96 for a fully managed inference pipeline including preprocessing and postprocessing I would recommend our YOLOv5 PyTorch Hub models. These include the NMS module you posted above and much more that allow for the simplest integration into your workflow possible. See PyTorch Hub Tutorial below to get started.

import torch

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')

# Images
dir = 'https://github.com/ultralytics/yolov5/raw/master/data/images/'
imgs = [dir + f for f in ('zidane.jpg', 'bus.jpg')]  # batch of images

# Inference
results = model(imgs)
results.print()  # or .show(), .save()

YOLOv5 Tutorials

@LeoSouquet
Copy link

Hi guys,
Coming from @rsundar96 I was wondering how to add this layer to my custom trained models ?
From the hub I can only get pre-existing models.

Thanks in advance,

regards

@glenn-jocher
Copy link
Member

glenn-jocher commented Apr 30, 2021

@LeoCyclope see YOLOv5 PyTorch Hub tutorial for loading custom models.

YOLOv5 Tutorials

Custom Models

This example loads a custom 20-class VOC-trained YOLOv5s model 'best.pt' with PyTorch Hub.

model = torch.hub.load('ultralytics/yolov5', 'custom', path_or_model='path/to/best.pt')  # custom model

@LeoSouquet
Copy link

Thanks for this :)
And if I want to add it without going through the torch.hub ?

Thanks in advance :)

@dragoncanfly
Copy link

Hi, have you got the way to add the postprocess(nms) in the whole model when export pytorch to onnx?

thanks in advance,

@glenn-jocher
Copy link
Member

@dragoncanfly no need, you can run exported ONNX models directly using PyTorch Hub:

Screenshot 2022-02-23 at 12 52 42

@dragoncanfly
Copy link

@dragoncanfly no need, you can run exported ONNX models directly using PyTorch Hub:

Screenshot 2022-02-23 at 12 52 42

hi, @glenn-jocher, I just want export a pytorch model (yolov3) which was trained by myself. So if there is a way to modify the net structure to enable the convert, of course, with postprocess I mean. Or is there any reference?

@glenn-jocher
Copy link
Member

@dragoncanfly You can directly implement non-maximum suppression (NMS) in the post-processing step of your PyTorch YOLOv3 model before exporting it to ONNX. You can refer to the official YOLOv3 implementation and specifically the nms algorithm present in the YOLO repository to understand how to incorporate NMS directly into the model architecture. This will ensure that the NMS step is included in the ONNX export. Good luck with your implementation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants