-
Notifications
You must be signed in to change notification settings - Fork 347
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
Removing eval in model weight API #2323
Conversation
Most of this API was copied from torchvision, let me check what their code looks like these days. |
I wonder if we can use torchvision's |
I looked at the torchvision version (https://github.com/pytorch/vision/blob/main/torchvision/models/_api.py#L108) and it seems more hacky than what I've implemented here. I updated the PR description with more details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More lines of code, but also more secure. This is also better from a type checking perspective, as eval
can return any type. We can think about how to delete this file and properly register our models in a separate PR.
* Removing eval * Extend the model_weights dict with sub weights * Just search through the sub weights enum * Ruff * Fix bug and mypy * Test coverage * Formatting --------- Co-authored-by: Adam J. Stewart <[email protected]>
Removing use of eval.
@nilsleh -- do you remember what the use case for eval was? If not, I say we replace all instances ofNevermind, I understand it now.get_weight
withget_model_weights
and removeget_weight
.get_weight(...)
allows a user to pass a string "ResNet18_Weights.LANDSAT_ETM_SR_MOCO" and get back the objectResNet18_Weights.LANDSAT_ETM_SR_MOCO
WeightEnum. Previously we did this witheval("ResNet18_Weights.LANDSAT_ETM_SR_MOCO")
which is bad. This proposed fix simply iterates through all available WeightEnums to look for matches and has the benefit of raising an error that makes sense if there is no match (vs. theeval(...)
which would do whatever).