-
Notifications
You must be signed in to change notification settings - Fork 370
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
load_state_dict does not return the model #1503
Conversation
Not sure why tests are failing but it's clearly unrelated to this PR. Will try to investigate in a separate PR. |
What's the error? |
@konstantinklemmer ping |
P.S. I fixed the failing test, tests should pass after updating your branch. I'm just curious why this PR is needed since it doesn't fail during testing. |
It's still unclear to me the purpose of this PR. What is the bug it is trying to solve? |
There isn't a bug, this is just an example of how to load pre-trained models differently. |
That's not what the PR descriptions says... |
The error that's being fixed is that |
This looks okay to me |
Fixed an error in the state dict loading of the turorial and added a comment on the num_classes parameter when creating timm models.
Thanks @isaaccorley, I understand the error now. It looks like we actually make this same mistake in the README. And we define our own custom I'm not sure about the num_classes comment. We aren't trying to teach people how to use timm, just how to use TorchGeo. I don't disagree that it's useful, just that it's in the wrong place. @konstantinklemmer let me know if you want me to make these changes myself. If I don't hear back I'll assume this PR has been abandoned and take over. |
Sorry, no idea why I am not getting notifications for this PR... Yes, I am happy to remove that comment and the example with |
Yes, and update the README and our builtin load_state_dict as well. Let me know if you want help with the latter. |
Yes please, I am not sure how to tackle the builtin |
It's not really a problem per se, just that we define a wrapper around |
Okay! So there are two functions that I found that, if I understand correctly, are relevant:
In both cases, if we want to keep them as standalone functions that return a model with weights loaded, we should probably rename them? |
We can either A) change the name, or B) change the return value to match |
Well, Then |
The builtin So you'll just return the output of that call so that our wrapper matches. |
Okay after some more digging, the
unless the |
Let's just return the output of -> Tuple[List[str], List[str]] I think that will work, and be correct. The builtin method has no return type annotations so it shouldn't complain that we aren't using a NamedTuple. If you have any trouble with mypy, let me know and I can hack on it. |
Got it! Will try if that works and report back. |
* Import Tuple from typing * Change return of `load_state_dict` from `model` to `Tuple[List[str], List[str]]`, matching the return of the standard PyTorch builtin function.
Remove example of loading pretrained model without prediction head (`num_classes=0`).
Adapt new `load_state_dict` function.
Ok I think I updated all files (the README, the notebook, the utils.py) but tests are failing. |
Yay! Thanks for helping with this - seems though that the original problem with the notebook test still persists? |
Completely unrelated problem, fixed in #1838 |
* Update pretrained_weights.ipynb Fixed an error in the state dict loading of the turorial and added a comment on the num_classes parameter when creating timm models. * Update docs/tutorials/pretrained_weights.ipynb * Update utils.py * Import Tuple from typing * Change return of `load_state_dict` from `model` to `Tuple[List[str], List[str]]`, matching the return of the standard PyTorch builtin function. * Update pretrained_weights.ipynb Remove example of loading pretrained model without prediction head (`num_classes=0`). * Update README.md Adapt new `load_state_dict` function. * Mimic return type of builtin load_state_dict * Modern type hints * Blacken * Try being explicit --------- Co-authored-by: Caleb Robinson <[email protected]> Co-authored-by: Adam J. Stewart <[email protected]>
Fixed an error in the state dict loading of the tutorial