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 using onnx model? #1800

Closed
Sun-Pak opened this issue Jul 1, 2021 · 11 comments
Closed

how to using onnx model? #1800

Sun-Pak opened this issue Jul 1, 2021 · 11 comments
Labels
question Further information is requested Stale Stale and schedule for closing soon

Comments

@Sun-Pak
Copy link

Sun-Pak commented Jul 1, 2021

❔Question

i create onnx model. using export.py. (using tutorial)
I loaded the onnx model, but don't know how to check the result.
I checked that the number of inputs is 1 and the number of outputs is 4,
I don't know why output is 4. I know that there should be 3 outputs.

i need help how i use it.

Additional context

232

And i edit onnx export in export.py
output_name = ['output']
aaaa

In Netron

sdsxc

I can't understand that result.

@Sun-Pak Sun-Pak added the question Further information is requested label Jul 1, 2021
@github-actions
Copy link

github-actions bot commented Jul 1, 2021

👋 Hello @Sun-Pak, 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 [email protected].

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.

@github-actions
Copy link

github-actions bot commented Aug 1, 2021

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv3 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv3 🚀 and Vision AI ⭐!

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Aug 1, 2021
@github-actions github-actions bot closed this as completed Aug 7, 2021
@matiassalriv1998
Copy link

❔Question

i create onnx model. using export.py. (using tutorial) I loaded the onnx model, but don't know how to check the result. I checked that the number of inputs is 1 and the number of outputs is 4, I don't know why output is 4. I know that there should be 3 outputs.

i need help how i use it.

Additional context

232

And i edit onnx export in export.py output_name = ['output'] aaaa

In Netron

sdsxc

I can't understand that result.

Did you get some information? I have a similar question.

The fields input and output are tensors, input tensor with your images shape and output tensor (this one's shape is something i don't understand well). I want to interpretate the output tensor in order to make inference on a video flux using C#.

@glenn-jocher
Copy link
Member

@matiassalriv1998 your ONNX model is out of date, export a new model with current code:

image

@glenn-jocher
Copy link
Member

glenn-jocher commented Sep 19, 2022

@matiassalriv1998 for C inference see export tutorial

@matiassalriv1998
Copy link

What I'm actually looking for is to get some light on how to interpretate the output tensor. That's the most important.

One thing I don't understand also is why 1x25200x7?? In older versions that numbers changes...

Here I paste my model with the latest version of yolo trained and exported:

onnModelNetron

After trying some changes on the script I got 4 output tensors by modifying the export.py according to: ultralytics/yolov5#343 (comment)), however I already have a code in C# which works with 3 output tensors with the standard form (1,3,20,20,7) (1,3,40,40,7) (1,3,80,80,7) which I would also like to know more about.

There's a lot of old information about and is a bit confusing for me, I would like some newer information which allows me to understand the tensor values, that's the most important for me.

@glenn-jocher
Copy link
Member

@matiassalriv1998 ONNX inference is very easy, just follow the Usage examples shown after export:

Screenshot 2022-09-19 at 13 59 59

@matiassalriv1998
Copy link

@matiassalriv1998 ONNX inference is very easy, just follow the Usage examples shown after export:

Screenshot 2022-09-19 at 13 59 59

As I mentioned before, inference is not my problem, I already know how to do an inference with that python line, the main goal I folow is to understand about the output tensor of .onnx model and why the numbers of the array by using the official Yolo repo [1,2500,7] or others I have seen at some places.

What I'm needing is to parse that output tensor (in C sharp) so I want to understand its form, there are ways to generate 4 tensors or 3 tensors as I explained before. Even I made a representative document with each visualization at netron.app for different configurations of export.py.

But that's my particular case, I'm just asking for some information about the output tensor form and its values.

@glenn-jocher
Copy link
Member

Dimension 2 indices are xywh, conf, class confidences

@matiassalriv1998
Copy link

(1, 25200, 7) Is my output tensor shape:

->1 is the batch size (set when exporting to .onnx)

->25200 is the bounding boxes number.
For an input of 640x640 we have to consider stride values 32, 16, 8. So 640/32=20, that means the image is "divided" on a
new 20x20 boxes image. Detections are made for that 3 stride values so 640/16=40 and 640/8=80. 3 bounding boxes are in
a box with the different anchors layers.
Conclusion: (20x20 + 40x40 + 80x80) x3=25200 bounding boxes

->7 according to @glenn-jocher comes from: [x y w h conf class0Conf class1Conf...] in my case I have 2 class detections so I
have 7 columns on my tensor output.

Tensor apparence is a float table of 25200x7 in my model. Actually I will try to process this tensor output instead of what I was doing with old code processing 3 tensors (1,80,7), (1,40,7),(1,20,7) which mades me export onnx by changing some parameters actually. But at least now I have some understanding about the tensor values.

I hope this have helped someone :)

@glenn-jocher
Copy link
Member

@matiassalriv1998 thanks for sharing your understanding of the output tensor's shape and values. It's great to see you've made progress in decoding the tensor output, and your explanation will certainly be helpful to others. If you have further questions or need additional assistance, feel free to ask!

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

No branches or pull requests

3 participants