-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Adding multiweight support for squeezenet prototype model #4817
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
Merged
datumbox
merged 3 commits into
pytorch:main
from
datumbox:prototype/squeezenet_multiweight
Nov 1, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import warnings | ||
from functools import partial | ||
from typing import Any, Optional | ||
|
||
from torchvision.transforms.functional import InterpolationMode | ||
|
||
from ...models.squeezenet import SqueezeNet | ||
from ..transforms.presets import ImageNetEval | ||
from ._api import Weights, WeightEntry | ||
from ._meta import _IMAGENET_CATEGORIES | ||
|
||
|
||
__all__ = ["SqueezeNet", "SqueezeNet1_0Weights", "SqueezeNet1_1Weights", "squeezenet1_0", "squeezenet1_1"] | ||
|
||
|
||
_common_meta = {"size": (224, 224), "categories": _IMAGENET_CATEGORIES, "interpolation": InterpolationMode.BILINEAR} | ||
|
||
|
||
class SqueezeNet1_0Weights(Weights): | ||
ImageNet1K_Community = WeightEntry( | ||
url="https://download.pytorch.org/models/squeezenet1_0-b66bff10.pth", | ||
transforms=partial(ImageNetEval, crop_size=224), | ||
meta={ | ||
**_common_meta, | ||
"recipe": "https://github.com/pytorch/vision/pull/49#issuecomment-277560717", | ||
"acc@1": 58.092, | ||
"acc@5": 80.420, | ||
}, | ||
) | ||
|
||
|
||
class SqueezeNet1_1Weights(Weights): | ||
ImageNet1K_Community = WeightEntry( | ||
url="https://download.pytorch.org/models/squeezenet1_1-b8a52dc0.pth", | ||
transforms=partial(ImageNetEval, crop_size=224), | ||
meta={ | ||
**_common_meta, | ||
"recipe": "https://github.com/pytorch/vision/pull/49#issuecomment-277560717", | ||
"acc@1": 58.178, | ||
"acc@5": 80.624, | ||
}, | ||
) | ||
|
||
|
||
def squeezenet1_0(weights: Optional[SqueezeNet1_0Weights] = None, progress: bool = True, **kwargs: Any) -> SqueezeNet: | ||
if "pretrained" in kwargs: | ||
warnings.warn("The argument pretrained is deprecated, please use weights instead.") | ||
weights = SqueezeNet1_0Weights.ImageNet1K_Community if kwargs.pop("pretrained") else None | ||
weights = SqueezeNet1_0Weights.verify(weights) | ||
if weights is not None: | ||
kwargs["num_classes"] = len(weights.meta["categories"]) | ||
|
||
model = SqueezeNet("1_0", **kwargs) | ||
|
||
if weights is not None: | ||
model.load_state_dict(weights.state_dict(progress=progress)) | ||
|
||
return model | ||
|
||
|
||
def squeezenet1_1(weights: Optional[SqueezeNet1_1Weights] = None, progress: bool = True, **kwargs: Any) -> SqueezeNet: | ||
if "pretrained" in kwargs: | ||
warnings.warn("The argument pretrained is deprecated, please use weights instead.") | ||
weights = SqueezeNet1_1Weights.ImageNet1K_Community if kwargs.pop("pretrained") else None | ||
weights = SqueezeNet1_1Weights.verify(weights) | ||
if weights is not None: | ||
kwargs["num_classes"] = len(weights.meta["categories"]) | ||
|
||
model = SqueezeNet("1_1", **kwargs) | ||
|
||
if weights is not None: | ||
model.load_state_dict(weights.state_dict(progress=progress)) | ||
|
||
return model |
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.
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.
Changed the enum convention for weights that come from the community and are not part of another library.