Skip to content

adding alexnet prototype model #4670

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
merged 4 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions torchvision/prototype/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .resnet import *
from .alexnet import *
from . import detection
from . import quantization
46 changes: 46 additions & 0 deletions torchvision/prototype/models/alexnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import warnings
from functools import partial
from typing import Any, Optional

from ...models.alexnet import AlexNet
from ..transforms.presets import ImageNetEval
from ._api import Weights, WeightEntry
from ._meta import _IMAGENET_CATEGORIES


__all__ = ["AlexNet", "AlexNetWeights", "alexnet"]


_common_meta = {
"size": (224, 224),
"categories": _IMAGENET_CATEGORIES,
}


class AlexNetWeights(Weights):
ImageNet1K_RefV1 = WeightEntry(
url="https://download.pytorch.org/models/alexnet-owt-7be5be79.pth",
transforms=partial(ImageNetEval, crop_size=224),
meta={
**_common_meta,
"recipe": "https://github.com/pytorch/vision/tree/main/references/classification#alexnet-and-vgg",
"acc@1": 56.522,
"acc@5": 79.066,
},
)


def alexnet(weights: Optional[AlexNetWeights] = None, progress: bool = True, **kwargs: Any) -> AlexNet:
if "pretrained" in kwargs:
warnings.warn("The argument pretrained is deprecated, please use weights instead.")
weights = AlexNetWeights.ImageNet1K_RefV1 if kwargs.pop("pretrained") else None
weights = AlexNetWeights.verify(weights)
if weights is not None:
kwargs["num_classes"] = len(weights.meta["categories"])

model = AlexNet(**kwargs)

if weights is not None:
model.load_state_dict(weights.state_dict(progress=progress))

return model