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

Fix model.save() for model YAMLs #18212

Merged
merged 8 commits into from
Dec 16, 2024
Merged

Fix model.save() for model YAMLs #18212

merged 8 commits into from
Dec 16, 2024

Conversation

Y-T-G
Copy link
Collaborator

@Y-T-G Y-T-G commented Dec 13, 2024

Closes #18206

MRE

from ultralytics import YOLO, ASSETS
model = YOLO("yolo11n.yaml")
model.save("saved.pt")

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Improves model consistency by updating how checkpoint data is managed during training and loading.

📊 Key Changes

  • Changed the default value of self.ckpt from None to an empty dictionary {} for better initialization.
  • Updated the train method to save both the model and checkpoint data (self.ckpt) after loading weights.

🎯 Purpose & Impact

  • 🛠 Improved Code Reliability: Ensures better handling of checkpoint-related data by initializing it as an empty dictionary, reducing potential runtime issues.
  • ⚙️ Enhanced Checkpoint Management: Exposes checkpoint data (ckpt) alongside the model post-training, providing users with more access to training-related information.
  • 💡 User Convenience: Easier debugging and usage of checkpoint data for advanced users, improving workflow transparency.

This change primarily benefits developers working with checkpoints and custom workflows, while maintaining backward compatibility. 🚀

@UltralyticsAssistant UltralyticsAssistant added bug Something isn't working fixed Bug has been resolved labels Dec 13, 2024
@UltralyticsAssistant
Copy link
Member

👋 Hello @Y-T-G, thank you for submitting an ultralytics/ultralytics 🚀 PR! To ensure a seamless integration of your work, please review the following checklist:

  • Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • Synchronize with Source: Confirm your PR is synchronized with the ultralytics/ultralytics main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • Update Documentation: Update the relevant documentation for any new or modified features.
  • Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
  • Minimize Changes: Limit your changes to the minimum necessary 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

For more guidance, please refer to our Contributing Guide.

From your PR diff and description, it looks like you are addressing a checkpoint-saving issue by ensuring self.ckpt is initialized. 🎉 This is a helpful improvement for robustness! However, if this change fixes a specific bug or issue, it would be great if you could provide a minimum reproducible example (MRE) demonstrating the error this PR resolves. This will help us validate and test your fix more efficiently.

This is an automated response, but don’t worry—a member of the Ultralytics team will review your PR and assist you soon. Let us know if you have any questions in the meantime. Thank you for contributing to Ultralytics! 🚀

Copy link

codecov bot commented Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.00%. Comparing base (626e42e) to head (e71ec70).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18212      +/-   ##
==========================================
- Coverage   78.52%   74.00%   -4.53%     
==========================================
  Files         128      128              
  Lines       17138    17138              
==========================================
- Hits        13458    12683     -775     
- Misses       3680     4455     +775     
Flag Coverage Δ
Benchmarks 35.03% <50.00%> (ø)
GPU 38.47% <100.00%> (-2.64%) ⬇️
Tests 67.76% <100.00%> (-4.67%) ⬇️

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.

@Laughing-q
Copy link
Member

@Y-T-G looks good! perhaps we could directly initialize self.ckpt={} at the first place instead of None, then I guess we don't need:

self.ckpt = self.ckpt or {}

@Y-T-G
Copy link
Collaborator Author

Y-T-G commented Dec 13, 2024

@Laughing-q Yeah, that sounds better

@glenn-jocher
Copy link
Member

@Y-T-G @Laughing-q there's a PEP violation that happens when initializing function arguments to non-immutable types like lists and dicts, but it's really annoying and I think we may want to start ignoring it, as otherwise the official standard is to initialize these to None and then have an if variable == None: then set it to what you originally wanted, i.e. variable = {}.

This is why you'll often see arguments initialized to None and then changed later in the code.

Signed-off-by: Glenn Jocher <[email protected]>
@glenn-jocher glenn-jocher changed the title Fix model.save() error when loading from yaml ultralytics 8.3.50 fix model.save() error when loading from YAML Dec 15, 2024
@glenn-jocher glenn-jocher changed the title ultralytics 8.3.50 fix model.save() error when loading from YAML ultralytics 8.3.50 fix model.save() for model YAMLs Dec 15, 2024
@glenn-jocher glenn-jocher changed the title ultralytics 8.3.50 fix model.save() for model YAMLs Fix model.save() for model YAMLs Dec 16, 2024
Signed-off-by: Glenn Jocher <[email protected]>
@glenn-jocher glenn-jocher merged commit f87b447 into main Dec 16, 2024
14 of 15 checks passed
@glenn-jocher glenn-jocher deleted the save-fix branch December 16, 2024 10:59
@glenn-jocher
Copy link
Member

@Y-T-G merged!

Y-T-G added a commit to namas191297/ultralytics that referenced this pull request Dec 17, 2024
Signed-off-by: Mohammed Yasin <[email protected]>
Signed-off-by: Glenn Jocher <[email protected]>
Co-authored-by: Glenn Jocher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Bug has been resolved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saving yolov6n crashes
4 participants