-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Adding multiweight support for inception prototype model #4821
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 4 commits into
pytorch:main
from
datumbox:prototype/inceptionv3_multiweights
Nov 1, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bbe6c89
Moving original builder at the bottom of the page to use proper typing.
datumbox 56e2b64
Adding multiweight support to inception.
datumbox ae3e47f
Update doc.
datumbox bf5fe2d
Merge branch 'main' into prototype/inceptionv3_multiweights
datumbox 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,54 @@ | ||
import warnings | ||
from functools import partial | ||
from typing import Any, Optional | ||
|
||
from torchvision.transforms.functional import InterpolationMode | ||
|
||
from ...models.inception import Inception3, InceptionOutputs, _InceptionOutputs | ||
from ..transforms.presets import ImageNetEval | ||
from ._api import Weights, WeightEntry | ||
from ._meta import _IMAGENET_CATEGORIES | ||
|
||
|
||
__all__ = ["Inception3", "InceptionOutputs", "_InceptionOutputs", "Inception3Weights", "inception_v3"] | ||
|
||
|
||
_common_meta = {"size": (299, 299), "categories": _IMAGENET_CATEGORIES, "interpolation": InterpolationMode.BILINEAR} | ||
|
||
|
||
class Inception3Weights(Weights): | ||
ImageNet1K_TFV1 = WeightEntry( | ||
url="https://download.pytorch.org/models/inception_v3_google-0cc3c7bd.pth", | ||
transforms=partial(ImageNetEval, crop_size=299, resize_size=342), | ||
meta={ | ||
**_common_meta, | ||
"recipe": "https://github.com/pytorch/vision/tree/main/references/classification#inception-v3", | ||
"acc@1": 77.294, | ||
"acc@5": 93.450, | ||
}, | ||
) | ||
|
||
|
||
def inception_v3(weights: Optional[Inception3Weights] = None, progress: bool = True, **kwargs: Any) -> Inception3: | ||
if "pretrained" in kwargs: | ||
warnings.warn("The argument pretrained is deprecated, please use weights instead.") | ||
weights = Inception3Weights.ImageNet1K_TFV1 if kwargs.pop("pretrained") else None | ||
weights = Inception3Weights.verify(weights) | ||
|
||
original_aux_logits = kwargs.get("aux_logits", True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to GoogleNet but here the default value is True not False |
||
if weights is not None: | ||
if "transform_input" not in kwargs: | ||
kwargs["transform_input"] = True | ||
kwargs["aux_logits"] = True | ||
kwargs["init_weights"] = False | ||
kwargs["num_classes"] = len(weights.meta["categories"]) | ||
|
||
model = Inception3(**kwargs) | ||
|
||
if weights is not None: | ||
model.load_state_dict(weights.state_dict(progress=progress)) | ||
if not original_aux_logits: | ||
model.aux_logits = False | ||
model.AuxLogits = None | ||
|
||
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.
Moving the builder at the bottom of the file to use proper typing.