Merged
Conversation
Codecov ReportAttention: Patch coverage is
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for loading pretrained models with mismatched channel sizes by filtering out incompatible weights during state dict loading. Key changes include:
- Adding a test in tests/test_base.py to verify mismatched keys are handled correctly.
- Updating load_state_dict in segmentation_models_pytorch/base/model.py to filter mismatched weights and issue a warning.
- Adjusting the inference notebook to use up-to-date installation instructions.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_base.py | Adds a test to ensure models load with mismatched keys while only specific layers are adjusted. |
| segmentation_models_pytorch/base/model.py | Modifies load_state_dict to filter out mismatched weights and warn the user. |
| examples/segformer_inference_pretrained.ipynb | Updates installation instructions to ensure the latest library versions are used. |
Files not reviewed (1)
- docs/save_load.rst: Language not supported
Comments suppressed due to low confidence (2)
segmentation_models_pytorch/base/model.py:138
- [nitpick] The warning message uses all caps and strong language, which may not be clear; consider rephrasing it to a more neutral and descriptive message (e.g., 'Mismatched key shapes detected; please retrain the model to update these layers:').
text = f"\n\n !!!!!! Mismatched keys !!!!!!\n\nYou should TRAIN the model to use it:\n{str_keys}\n"
segmentation_models_pytorch/base/model.py:139
- [nitpick] Using 'stacklevel=-1' may not provide the expected context for the warning; consider using a more conventional stacklevel (such as 2) to point to the relevant caller.
warnings.warn(text, stacklevel=-1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows to load pretrained model with different number of channels
For example:
Reported in: