-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
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
Fix ONNX export using --grid --simplify --dynamic simultaneously #2982
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Hello @jylink, thank you for submitting a 🚀 PR! To allow your work to be integrated as seamlessly as possible, we advise you to:
- ✅ Verify your PR is up-to-date with origin/master. If your PR is behind origin/master an automatic GitHub actions rebase may be attempted by including the /rebase command in a comment body, or by running the following code, replacing 'feature' with the name of your local branch:
git remote add upstream https://github.com/ultralytics/yolov5.git
git fetch upstream
git checkout feature # <----- replace 'feature' with local branch name
git rebase upstream/master
git push -u origin -f
- ✅ Verify all Continuous Integration (CI) checks are passing.
- ✅ Reduce changes to the absolute minimum required for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." -Bruce Lee
@jylink thanks for the PR! I've just now merged a similar modification to the Detect() layer in 'YOLOv5 AWS Inferentia Inplace compatibility updates' #2953 which implements some of the same updates and will cause a conflict with this PR. Once #2953 is merged please merge master in your branch, resolving conflicts as they appear. You may also be able to recycle the new Detect layer |
@jylink this looks a lot better, thanks for the updates! Will review later today. |
@jylink I've taken the opportunity here to streamline the export a bit:
Can you verify these 3 use cases on your side and let me know what you think?
|
@jylink I think perhaps the -1 in the .view() call is causing problems in yolo.py L38. Can you try replacing these lines with the explicit shape below and see if this fixes the problem? Ideally we do not want to add operations in the forward method as these will run on every image, which is expensive. If this solution works you can revert your yolo.py L60 addition. Replace: |
@jylink also I think your L60 addition may have a bug, as |
They are ok
Simplify failed
Changed |
@jluntamazon would this PR update to this line affect your use-case? The change would be applied to yolo.py L61 and add a |
That should be fine for our use-case, the main operation I was avoiding in the original PR was slice assignment |
@jluntamazon thanks for the feedback! @jylink PR is merged! Thank you for your contributions. |
…ralytics#2982) * Update yolo.py * Update export.py * fix export grid * Update export.py, remove detect export attribute * rearrange if order * remove --grid, default inplace=False * rename exp_dynamic to onnx_dynamic, comment * replace bs with 1 in anchor_grid[i] index 0 * Update export.py Co-authored-by: Glenn Jocher <[email protected]>
…ralytics#2982) * Update yolo.py * Update export.py * fix export grid * Update export.py, remove detect export attribute * rearrange if order * remove --grid, default inplace=False * rename exp_dynamic to onnx_dynamic, comment * replace bs with 1 in anchor_grid[i] index 0 * Update export.py Co-authored-by: Glenn Jocher <[email protected]>
…ralytics#2982) * Update yolo.py * Update export.py * fix export grid * Update export.py, remove detect export attribute * rearrange if order * remove --grid, default inplace=False * rename exp_dynamic to onnx_dynamic, comment * replace bs with 1 in anchor_grid[i] index 0 * Update export.py Co-authored-by: Glenn Jocher <[email protected]> (cherry picked from commit b292837)
…ralytics#2982) * Update yolo.py * Update export.py * fix export grid * Update export.py, remove detect export attribute * rearrange if order * remove --grid, default inplace=False * rename exp_dynamic to onnx_dynamic, comment * replace bs with 1 in anchor_grid[i] index 0 * Update export.py Co-authored-by: Glenn Jocher <[email protected]>
python models/export.py --grid --dynamic --simplify
failed to export onnx model.#2856 fix dynamic and simplify but still cannot work with grid, because the
self.grid[i]
mismatch the dynamicy[..., 0:2]
. This pull request fixes it.Also the removal of subscript assignments helps to avoid unsupported ScatterND nodes, so the onnx exported using
--grid
can be directly converted to tensorRT engine now🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Improved ONNX export flexibility for YOLOv5.
📊 Key Changes
--grid
flag from the command-line arguments inexport.py
.--inplace
flag to control theinplace
parameter for the YOLOv5 Detect() layer.🎯 Purpose & Impact
--inplace
flag provides users with the option to choose how Detect() processes inputs, which could lead to memory optimizations.