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

convert ONNX outputs to Bbox #8085

Closed
1 of 2 tasks
chen2mg opened this issue Jun 3, 2022 · 7 comments
Closed
1 of 2 tasks

convert ONNX outputs to Bbox #8085

chen2mg opened this issue Jun 3, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@chen2mg
Copy link

chen2mg commented Jun 3, 2022

Search before asking

  • I have searched the YOLOv5 issues and found no similar feature requests.

Description

I converted my customized "yolo.pt" model to "yolo.onnx".

The output dimensions are:
Screen Shot 2022-06-02 at 10 40 23 PM

I have read #708

people suggested "non_max_suppression", but I still have trouble to feed outputs from onnx to "non_max_suppression".

can some one be more specific?

how to convert:
[1, 25200, 7]
[1,3,80, 80,7]
[1,3,40, 40,7]
[1,3,20, 20,7]
to Bbox, labels?

Thank you so much!

Use case

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@chen2mg chen2mg added the enhancement New feature or request label Jun 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2022

👋 Hello @chen2mg, thank you for your interest in YOLOv5 🚀! 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://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 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 YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@AyushExel
Copy link
Contributor

@chen2mg You can use detect.py to run inference on exported models directly.
python path/to/detect.py --yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn

@glenn-jocher
Copy link
Member

@chen2mg your code is out of date. To update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

@chen2mg
Copy link
Author

chen2mg commented Jun 3, 2022

@chen2mg You can use detect.py to run inference on exported models directly. python path/to/detect.py --yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn

Thank you for your reply.
I also need to deploy this onnx model on Javascript, so I need to know how to convert [1, 25200, 7] to Bbox.

@chen2mg
Copy link
Author

chen2mg commented Jun 3, 2022

@chen2mg your code is out of date. To update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

Thank you for your reply. What do you mean? the export.py I used is out of date?

@chen2mg
Copy link
Author

chen2mg commented Jun 3, 2022

problem solve by:

# outputs[0]: (1, 25200, 7)
y = torch.tensor(outputs[0]) if isinstance(outputs[0], np.ndarray) else outputs[0]
pred = non_max_suppression(y)
print(pred)

#[tensor([[163.18411, 270.04858, 350.99985, 399.60071,   0.93833,   1.00000],
#        [ 62.01051, 235.79718, 543.79761, 432.11530,   0.93351,   0.00000]])]

Thanks

@chen2mg chen2mg closed this as completed Jun 3, 2022
@glenn-jocher
Copy link
Member

@chen2mg glad to hear that you were able to solve the problem! If you have any more questions or need further assistance, feel free to ask. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants