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

ONNX export Path to str() #12177

Merged
merged 4 commits into from
Sep 29, 2023
Merged

ONNX export Path to str() #12177

merged 4 commits into from
Sep 29, 2023

Conversation

Doquey
Copy link
Contributor

@Doquey Doquey commented Sep 28, 2023

🤖 Generated by Copilot at 929bc87

Summary

🐛🔧📝

Fix a bug in export.py that caused a TypeError when exporting models to ONNX format. Convert the f variable to a string before passing it to torch.onnx.export.

f becomes a string
To avoid TypeError
Winter bug is fixed

Walkthrough

  • Fix a bug that causes a TypeError when exporting to ONNX format (link)

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Enhanced export compatibility for ONNX files in 'ultralytics/yolov5'.

📊 Key Changes

  • Altered the file path conversion to a string when defining the .onnx file name during export.

🎯 Purpose & Impact

  • Purpose: This change ensures consistent handling of file paths across different environments, potentially preventing issues related to file path representations.
  • Impact: Users exporting their YOLOv5 models to ONNX format will benefit from improved reliability, with reduced risk of export-related errors or compatibility issues across various platforms. 🔄📈

Doquey and others added 4 commits September 28, 2023 15:41
Signed-off-by: Luis Filipe Araujo de Souza <58831491+Doquey@users.noreply.github.com>
Signed-off-by: Luis Filipe Araujo de Souza <58831491+Doquey@users.noreply.github.com>
Transformed the f variable into a string on the export onnx. This bug was making it impossible to export any models in .onnx, since it was making the typehint not accept the users input as it is specified in the functions documentation

Signed-off-by: Luis Filipe Araujo de Souza <58831491+Doquey@users.noreply.github.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Hello @Doquey, thank you for submitting a YOLOv5 🚀 PR! To allow your work to be integrated as seamlessly as possible, we advise you to:

  • ✅ Verify your PR is up-to-date with ultralytics/yolov5 master branch. If your PR is behind you can update your code by clicking the 'Update branch' button or by running git pull and git merge master locally.
  • ✅ Verify all YOLOv5 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

@Doquey
Copy link
Contributor Author

Doquey commented Sep 28, 2023

Its a very simple fix to a annoying bug that was happening when I was trying to export my yolov5m.pt model into a .onnx model.

ONNX: export failure ❌ 0.0s: Function torch.onnx.utils.export() parameter f="PosixPath('best.onnx')" violates type hint typing.Union[str, _io.BytesIO], as <protocol "pathlib.PosixPath"> "PosixPath('best.onnx')" not str or <class "_io.BytesIO">.

The only thing I did was go into the function that was trying to export the model in .onnx and add a str() to the f variable before pasing it to the onnx.utils.export() function

@glenn-jocher
Copy link
Member

@Doquey thank you for bringing this bug to our attention and for providing a simple fix. We appreciate your contribution!

We understand how frustrating it can be when encountering errors like this during the model export process. Your fix of converting the f variable to a string before passing it to the torch.onnx.export function is indeed the correct solution.

We value your input and appreciate your effort in helping us improve YOLOv5. Your contribution will help ensure a smoother experience for all users.

Thank you once again for your contribution to the YOLOv5 project.

@glenn-jocher glenn-jocher changed the title Bugfix ONNX export Path to str() Sep 29, 2023
@glenn-jocher glenn-jocher merged commit bb9706e into ultralytics:master Sep 29, 2023
pleb631 pushed a commit to pleb631/yolov5 that referenced this pull request Jan 6, 2024
* Update export.py

Signed-off-by: Luis Filipe Araujo de Souza <58831491+Doquey@users.noreply.github.com>

* Update export.py

Signed-off-by: Luis Filipe Araujo de Souza <58831491+Doquey@users.noreply.github.com>

* Update export.py

Transformed the f variable into a string on the export onnx. This bug was making it impossible to export any models in .onnx, since it was making the typehint not accept the users input as it is specified in the functions documentation

Signed-off-by: Luis Filipe Araujo de Souza <58831491+Doquey@users.noreply.github.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: Luis Filipe Araujo de Souza <58831491+Doquey@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

2 participants