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

intersect_dicts() in hubconf.py fix #5542

Merged
merged 1 commit into from Nov 6, 2021
Merged

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Nov 6, 2021

Fix for #2609 (comment)

import torch

for ch in 1, 3, 4, 10:
    model = torch.hub.load('ultralytics/yolov5', 'yolov5s', channels=ch)
    results = model(np.array((640, 640, ch)))
    results.print()

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Refactoring and cleanup of the intersection logic used in model state dict updates.

📊 Key Changes

  • intersect_dicts function moved from utils/torch_utils.py to utils/general.py.
  • Updated references to intersect_dicts in hubconf.py and train.py to reflect its new location.
  • Now using intersect_dicts during model initialization in hubconf.py to filter checkpoint state_dict before loading.

🎯 Purpose & Impact

  • This refactoring improves code modularity and maintainability by placing intersect_dicts in a more general utility file.
  • It ensures that only relevant parts of the pretrained model checkpoints are loaded, preventing potential shape mismatches and excluding specific keys when necessary.
  • Users will benefit from a more robust and error-resistant model loading process, potentially improving the ease of use and reliability of the YOLOv5 models.

@glenn-jocher glenn-jocher self-assigned this Nov 6, 2021
@glenn-jocher glenn-jocher linked an issue Nov 6, 2021 that may be closed by this pull request
@glenn-jocher glenn-jocher merged commit e189fa1 into master Nov 6, 2021
@glenn-jocher glenn-jocher deleted the update/intersect_dicts branch November 6, 2021 14:41
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
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.

Single channel image training?
1 participant