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

Apply make_divisible for ONNX models in Autoshape #10172

Merged
merged 4 commits into from
Nov 17, 2022

Conversation

janus-zheng
Copy link
Contributor

@janus-zheng janus-zheng commented Nov 16, 2022

At line 697 we have this make_divisible function applied on input images for pytorch models.

  • Context: we want to run inference on varied input sizes instead of fixed image size.
  • When I test an image of size [720, 720] for a pytorch model (e.g., yolov5n.pt), we can see that it will be reshaped to [736, 736] by the function. This is as expected.
  • When I test the same image for the onnx model (e.g., yolov5n.onnx, exported with --dynamic), I got an error and it's due to the indivisible problem
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running Concat node. Name:'Concat_143' Status Message: concat.cc:156 PrepareForCompute Non concat axis dimensions must match: Axis 3 has mismatched dimensions of 45 and 46

The simple solution is to enable the make_divisible function for onnx model too.

Signed-off-by: janus-zheng 106574221+janus-zheng@users.noreply.github.com

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Enhanced image pre-processing in YOLOv5's inference pipeline.

πŸ“Š Key Changes

  • Streamlined the image sizing process during the inference stage, removing a conditional check for PyTorch training.

🎯 Purpose & Impact

  • πŸ‘ Improves the efficiency of image pre-processing by eliminating unnecessary code when not in training mode.
  • πŸš€ Potentially increases the speed of model inference, leading to faster results for end-users.
  • πŸ§‘β€πŸ’» Provides a more simplified codebase for developers working with the inference part of YOLOv5's code.

janus-zheng and others added 3 commits November 16, 2022 18:56
At line 697 we have this `make_divisible` function for pytorch models. 
* Context: we want to run inference on varied input sizes instead of fixed image size.
* When I test an image of size [720, 720] for a pytorch model (e.g., yolov5n.pt), we can see that it will be reshaped to [736, 736] by the function. This is as expected.
* When I test the same image for the onnx model (e.g., yolov5n.onnx, exported with `--dynamic`), I got an error and it's due to the indivisible problem
```
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running Concat node. Name:'Concat_143' Status Message: concat.cc:156 PrepareForCompute Non concat axis dimensions must match: Axis 3 has mismatched dimensions of 45 and 46
```

The simple solution is to enable the `make_divisible` function for onnx model too.

Signed-off-by: janus-zheng <106574221+janus-zheng@users.noreply.github.com>
Signed-off-by: janus-zheng <106574221+janus-zheng@users.noreply.github.com>
All formats from DetectMultiBackend should have default stride=32

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
@glenn-jocher glenn-jocher changed the title Apply make_divisible for onnx models in Autoshape Apply make_divisible for ONNX models in Autoshape Nov 16, 2022
@glenn-jocher
Copy link
Member

@janus-zheng I've updated this to apply to all models, as they should all inherit a default stride=32 on DetectMultiBackend init here:

stride = 32 # default stride

Does this work for you?

@janus-zheng
Copy link
Contributor Author

@janus-zheng I've updated this to apply to all models, as they should all inherit a default stride=32 on DetectMultiBackend init here:

stride = 32 # default stride

Does this work for you?

@glenn-jocher that's better, thanks!

@glenn-jocher glenn-jocher merged commit a9f895d into ultralytics:master Nov 17, 2022
@glenn-jocher
Copy link
Member

@janus-zheng perfect. PR is merged. Thank you for your contributions to YOLOv5 πŸš€ and Vision AI ⭐

@janus-zheng janus-zheng deleted the patch-2 branch November 17, 2022 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants