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. |
adamjstewart
left a comment
There was a problem hiding this comment.
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 <ajstewart426@gmail.com>
|
Published CVE for reference: https://www.cve.org/CVERecord?id=CVE-2024-49048 |
|
And published GitHub advisory: GHSA-ghq9-vc6f-8qjf |
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_weightwithget_model_weightsand 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_MOCOWeightEnum. 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).