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

Custom folder for export artifacts #11817

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

mayorblock
Copy link

@mayorblock mayorblock commented May 9, 2024

In some situations it can be useful to be able to specify the output location of exported artifacts (for example, training on remove and storing on some mounted storage). This is an answer to #4503 that discuss this option in the context of ONNX. It turned out that with minimal changes it can work for most (all?) the rest which are included

I somewhat arbitrarily picked artifact_path for the new optional configuration parameter (I am very much open for better alternatives :).

I have had to split the artifact location from the input model location; they where tightly coupled before. It works with both absolute and relative (to current working directory). Currently it copies the artifact name from the input model but that could of course be adjusted, if you find that useful.

I hope you find this contribution useful and I very much looks forward to hear your opinions / comments.

I have extended and run the unit tests as much as possible but work on a mac. I was not able to run some of the LINUX-enabled only formats. Also I have not yet looked into enabling this in the cli (but will do)

Cheers
Mikael

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Improved model export functionality with temporary directories for safer file handling.

πŸ“Š Key Changes

  • πŸ›  Added tempfile usage to create temporary directories during model exports.
  • πŸ”„ Changed model export tests to use these temporary directories to ensure that files are handled in a safe and controlled environment.
  • 🎨 Minor code reorganization and optimizations across various files for better readability and performance.

🎯 Purpose & Impact

  • πŸŽ‰ Enhanced Safety: Using temporary directories during model exports avoids conflicts and potential data loss, making the process safer and more reliable.
  • 🧹 Code Cleanup: The reorganization and minor optimizations help maintain the codebase, making it easier to manage and understand.
  • πŸš€ User Experience: These changes contribute to a more robust and error-resistant environment, potentially improving user satisfaction by minimizing unexpected issues.

Copy link

github-actions bot commented May 9, 2024

All Contributors have signed the CLA. βœ…
Posted by the CLA Assistant Lite bot.

Copy link

@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 @mayorblock, thank you for submitting an Ultralytics YOLOv8 πŸš€ 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/ultralytics main 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 main locally.
  • βœ… Verify all YOLOv8 Continuous Integration (CI) checks are passing.
  • βœ… Update YOLOv8 Docs for any new or updated features.
  • βœ… 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

See our Contributing Guide for details and let us know if you have any questions!

Copy link

codecov bot commented May 10, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 68.45%. Comparing base (b3dfbdd) to head (f64d141).

Files Patch % Lines
ultralytics/engine/exporter.py 84.21% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11817      +/-   ##
==========================================
- Coverage   70.63%   68.45%   -2.18%     
==========================================
  Files         122      122              
  Lines       15631    15635       +4     
==========================================
- Hits        11041    10703     -338     
- Misses       4590     4932     +342     
Flag Coverage Ξ”
Benchmarks 35.37% <85.71%> (-0.17%) ⬇️
GPU ?
Tests 66.66% <57.14%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@mayorblock
Copy link
Author

I have read the CLA Document and I sign the CLA

@Burhan-Q Burhan-Q added the enhancement New feature or request label May 13, 2024
@Burhan-Q
Copy link
Member

Burhan-Q commented May 13, 2024

@mayorblock have you investigated the idea of using the ckpt_path attribute instead? This would mean that a new argument wouldn't be required. Currently the model.model.pt_path attribute is used, but it would be nice to use an existing attribute or argument to accomplish the same functionality, as we're already contending with a large number of arguments. I did a quick test to see if using the pt_path attribute would change the output filename, and it did update as expected.

from ultralytics import YOLO

model = YOLO("yolov8n.pt")
model.model.pt_path = "yolov8n-custom-name.pt"
out = model.export(format="onnx")

print(out)
>>> 'yolov8n-custom-name.onnx'

This did not work if I added a directory model.model.pt_path = "new_path/yolov8n-custom-name.pt" so if you wanted to try to create a directory using this, code would need to be added to verify the directory existed and to create one if not (this might work if the directory exists). I did not attempt with an absolute directory elsewhere with this example, so you may find that could be problematic or adds complexity.

If possible, it would be nice to use a higher level attribute (like the previously mentioned model.ckpt_path or even model.model_name) to set the output location instead. There's also the project and name arguments that are used with training, which might be another area to investigate, but I suspect the attributes might be a simpler solution.

@mayorblock
Copy link
Author

@Burhan-Q thank you for the suggestions. I did notice that model.pt_path was used for export location, also with (existing) folder included. I would definitely prefer not to use this one to specify export location (as I understand it this is not what you are suggestion either).

I had more distinct decoupling in mind but your point to avoid introduction of additional (minor) arguments is a very valid one. I will have a look at model.ckpt_path to see it if can work and get back with a suggestion.

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

Successfully merging this pull request may close these issues.

None yet

4 participants