Skip to content

Reinstate and deprecate model_urls and quant_model_urls #5992

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 36 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
82f4f3d
Reinstate and deprecate `model_urls` and `quant_model_urls`
datumbox May 11, 2022
9f4d9b5
Apply suggestions from code review
datumbox May 11, 2022
d4e406a
Move todo location
datumbox May 11, 2022
faed8f5
Add alexnet
datumbox May 11, 2022
8d329ba
Add densenet
datumbox May 11, 2022
b58579d
Add efficientnet
datumbox May 11, 2022
4e5b6e2
Add googlenet.
datumbox May 11, 2022
d3fa473
Add inception.
datumbox May 11, 2022
1304a30
Add mobilenetv3
datumbox May 11, 2022
d3867b7
Add regnet
datumbox May 11, 2022
e483183
Add resnet
datumbox May 11, 2022
aea12c4
Add shufflenetv2
datumbox May 11, 2022
4396b81
Fix linter
datumbox May 12, 2022
e55f24b
Add squeezenet
datumbox May 12, 2022
619fa2b
Add vgg
datumbox May 12, 2022
9984e3f
Add vit
datumbox May 12, 2022
184b9ef
Add quantized googlenet
datumbox May 12, 2022
fdb275e
Add quantized inceptionv3
datumbox May 12, 2022
4af3b38
Add quantized mobilenet_v3
datumbox May 12, 2022
f54e6b7
Add quantized resnet
datumbox May 12, 2022
e1aebba
Add quantized shufflenetv2
datumbox May 12, 2022
5480e3e
Fix incorrect imports
datumbox May 12, 2022
0c81ca5
Add faster_rcnn
datumbox May 12, 2022
cf7908a
Add fcos
datumbox May 12, 2022
9767477
Add keypoint rcnn
datumbox May 12, 2022
ff8d6cd
Add mask rcnn
datumbox May 12, 2022
0c60179
Add retinanet
datumbox May 12, 2022
da54d93
Add ssd
datumbox May 12, 2022
cb8255c
Add ssdlite
datumbox May 12, 2022
98d2a4d
Add deeplabv3
datumbox May 12, 2022
e678707
Add fcn
datumbox May 12, 2022
261bf61
Add lraspp.
datumbox May 12, 2022
c3ad739
Add video resnet
datumbox May 12, 2022
4ed1440
Removing weights for shufflenetv2_x1.5 and shufflenetv2_x2.0
datumbox May 12, 2022
a74eaf2
Update the comments
datumbox May 12, 2022
4019df1
Merge branch 'main' into models/model_urls
datumbox May 12, 2022
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
18 changes: 15 additions & 3 deletions torchvision/models/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def wrapper(*args: Any, **kwargs: Any) -> D:
keyword_only_kwargs = dict(zip(keyword_only_params, keyword_only_args))
warnings.warn(
f"Using {sequence_to_str(tuple(keyword_only_kwargs.keys()), separate_last='and ')} as positional "
f"parameter(s) is deprecated. Please use keyword parameter(s) instead."
f"parameter(s) is deprecated since 0.13 and will be removed in 0.15. Please use keyword parameter(s) "
f"instead."
)
kwargs.update(keyword_only_kwargs)

Expand Down Expand Up @@ -205,11 +206,13 @@ def inner_wrapper(*args: Any, **kwargs: Any) -> M:

if not pretrained_positional:
warnings.warn(
f"The parameter '{pretrained_param}' is deprecated, please use '{weights_param}' instead."
f"The parameter '{pretrained_param}' is deprecated since 0.13 and will be removed in 0.15, "
f"please use '{weights_param}' instead."
)

msg = (
f"Arguments other than a weight enum or `None` for '{weights_param}' are deprecated. "
f"Arguments other than a weight enum or `None` for '{weights_param}' are deprecated since 0.13 and "
f"will be removed in 0.15. "
f"The current behavior is equivalent to passing `{weights_param}={default_weights_arg}`."
)
if pretrained_arg:
Expand Down Expand Up @@ -242,3 +245,12 @@ def _ovewrite_value_param(param: Optional[V], new_value: V) -> V:
if param != new_value:
raise ValueError(f"The parameter '{param}' expected value {new_value} but got {param} instead.")
return new_value


class _ModelURLs(dict):
def __getitem__(self, item):
warnings.warn(
"Accessing the model URLs via the internal dictionary of the module is deprecated since 0.13 and will "
"be removed in 0.15. Please access them via the appropriate Weights Enum instead."
)
return super().__getitem__(item)
11 changes: 11 additions & 0 deletions torchvision/models/alexnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,14 @@ def alexnet(*, weights: Optional[AlexNet_Weights] = None, progress: bool = True,
model.load_state_dict(weights.get_state_dict(progress=progress))

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from ._utils import _ModelURLs


model_urls = _ModelURLs(
{
"alexnet": AlexNet_Weights.IMAGENET1K_V1.url,
}
)
14 changes: 14 additions & 0 deletions torchvision/models/densenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,17 @@ def densenet201(*, weights: Optional[DenseNet201_Weights] = None, progress: bool
weights = DenseNet201_Weights.verify(weights)

return _densenet(32, (6, 12, 48, 32), 64, weights, progress, **kwargs)


# The dictionary below is internal implementation detail and will be removed in v0.15
from ._utils import _ModelURLs


model_urls = _ModelURLs(
{
"densenet121": DenseNet121_Weights.IMAGENET1K_V1.url,
"densenet169": DenseNet169_Weights.IMAGENET1K_V1.url,
"densenet201": DenseNet201_Weights.IMAGENET1K_V1.url,
"densenet161": DenseNet161_Weights.IMAGENET1K_V1.url,
}
)
13 changes: 13 additions & 0 deletions torchvision/models/detection/faster_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,16 @@ def fasterrcnn_mobilenet_v3_large_fpn(
trainable_backbone_layers=trainable_backbone_layers,
**kwargs,
)


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs


model_urls = _ModelURLs(
{
"fasterrcnn_resnet50_fpn_coco": FasterRCNN_ResNet50_FPN_Weights.COCO_V1.url,
"fasterrcnn_mobilenet_v3_large_320_fpn_coco": FasterRCNN_MobileNet_V3_Large_320_FPN_Weights.COCO_V1.url,
"fasterrcnn_mobilenet_v3_large_fpn_coco": FasterRCNN_MobileNet_V3_Large_FPN_Weights.COCO_V1.url,
}
)
11 changes: 11 additions & 0 deletions torchvision/models/detection/fcos.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,3 +758,14 @@ def fcos_resnet50_fpn(
model.load_state_dict(weights.get_state_dict(progress=progress))

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs


model_urls = _ModelURLs(
{
"fcos_resnet50_fpn_coco": FCOS_ResNet50_FPN_Weights.COCO_V1.url,
}
)
13 changes: 13 additions & 0 deletions torchvision/models/detection/keypoint_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,16 @@ def keypointrcnn_resnet50_fpn(
overwrite_eps(model, 0.0)

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs


model_urls = _ModelURLs(
{
# legacy model for BC reasons, see https://github.com/pytorch/vision/issues/1606
"keypointrcnn_resnet50_fpn_coco_legacy": KeypointRCNN_ResNet50_FPN_Weights.COCO_LEGACY.url,
"keypointrcnn_resnet50_fpn_coco": KeypointRCNN_ResNet50_FPN_Weights.COCO_V1.url,
}
)
11 changes: 11 additions & 0 deletions torchvision/models/detection/mask_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,14 @@ def maskrcnn_resnet50_fpn_v2(
model.load_state_dict(weights.get_state_dict(progress=progress))

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs


model_urls = _ModelURLs(
{
"maskrcnn_resnet50_fpn_coco": MaskRCNN_ResNet50_FPN_Weights.COCO_V1.url,
}
)
11 changes: 11 additions & 0 deletions torchvision/models/detection/retinanet.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,14 @@ def retinanet_resnet50_fpn_v2(
model.load_state_dict(weights.get_state_dict(progress=progress))

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs


model_urls = _ModelURLs(
{
"retinanet_resnet50_fpn_coco": RetinaNet_ResNet50_FPN_Weights.COCO_V1.url,
}
)
22 changes: 22 additions & 0 deletions torchvision/models/detection/ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,25 @@ def ssd300_vgg16(
model.load_state_dict(weights.get_state_dict(progress=progress))

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs


model_urls = _ModelURLs(
{
"ssd300_vgg16_coco": SSD300_VGG16_Weights.COCO_V1.url,
}
)


backbone_urls = _ModelURLs(
{
# We port the features of a VGG16 backbone trained by amdegroot because unlike the one on TorchVision, it uses
# the same input standardization method as the paper.
# Ref: https://s3.amazonaws.com/amdegroot-models/vgg16_reducedfc.pth
# Only the `features` weights have proper values, those on the `classifier` module are filled with nans.
"vgg16_features": VGG16_Weights.IMAGENET1K_FEATURES.url,
}
)
11 changes: 11 additions & 0 deletions torchvision/models/detection/ssdlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,14 @@ def ssdlite320_mobilenet_v3_large(
model.load_state_dict(weights.get_state_dict(progress=progress))

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs


model_urls = _ModelURLs(
{
"ssdlite320_mobilenet_v3_large_coco": SSDLite320_MobileNet_V3_Large_Weights.COCO_V1.url,
}
)
20 changes: 20 additions & 0 deletions torchvision/models/efficientnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,3 +1028,23 @@ def efficientnet_v2_l(
norm_layer=partial(nn.BatchNorm2d, eps=1e-03),
**kwargs,
)


# The dictionary below is internal implementation detail and will be removed in v0.15
from ._utils import _ModelURLs


model_urls = _ModelURLs(
{
# Weights ported from https://github.com/rwightman/pytorch-image-models/
"efficientnet_b0": EfficientNet_B0_Weights.IMAGENET1K_V1.url,
"efficientnet_b1": EfficientNet_B1_Weights.IMAGENET1K_V1.url,
"efficientnet_b2": EfficientNet_B2_Weights.IMAGENET1K_V1.url,
"efficientnet_b3": EfficientNet_B3_Weights.IMAGENET1K_V1.url,
"efficientnet_b4": EfficientNet_B4_Weights.IMAGENET1K_V1.url,
# Weights ported from https://github.com/lukemelas/EfficientNet-PyTorch/
"efficientnet_b5": EfficientNet_B5_Weights.IMAGENET1K_V1.url,
"efficientnet_b6": EfficientNet_B6_Weights.IMAGENET1K_V1.url,
"efficientnet_b7": EfficientNet_B7_Weights.IMAGENET1K_V1.url,
}
)
12 changes: 12 additions & 0 deletions torchvision/models/googlenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,15 @@ def googlenet(*, weights: Optional[GoogLeNet_Weights] = None, progress: bool = T
)

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from ._utils import _ModelURLs


model_urls = _ModelURLs(
{
# GoogLeNet ported from TensorFlow
"googlenet": GoogLeNet_Weights.IMAGENET1K_V1.url,
}
)
12 changes: 12 additions & 0 deletions torchvision/models/inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,15 @@ def inception_v3(*, weights: Optional[Inception_V3_Weights] = None, progress: bo
model.AuxLogits = None

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from ._utils import _ModelURLs


model_urls = _ModelURLs(
{
# Inception v3 ported from TensorFlow
"inception_v3_google": Inception_V3_Weights.IMAGENET1K_V1.url,
}
)
11 changes: 11 additions & 0 deletions torchvision/models/mobilenetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,14 @@ def mobilenet_v2(
model.load_state_dict(weights.get_state_dict(progress=progress))

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from ._utils import _ModelURLs


model_urls = _ModelURLs(
{
"mobilenet_v2": MobileNet_V2_Weights.IMAGENET1K_V1.url,
}
)
12 changes: 12 additions & 0 deletions torchvision/models/mobilenetv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,15 @@ def mobilenet_v3_small(

inverted_residual_setting, last_channel = _mobilenet_v3_conf("mobilenet_v3_small", **kwargs)
return _mobilenet_v3(inverted_residual_setting, last_channel, weights, progress, **kwargs)


# The dictionary below is internal implementation detail and will be removed in v0.15
from ._utils import _ModelURLs


model_urls = _ModelURLs(
{
"mobilenet_v3_large": MobileNet_V3_Large_Weights.IMAGENET1K_V1.url,
"mobilenet_v3_small": MobileNet_V3_Small_Weights.IMAGENET1K_V1.url,
}
)
13 changes: 13 additions & 0 deletions torchvision/models/quantization/googlenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,16 @@ def googlenet(
)

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs
from ..googlenet import model_urls # noqa: F401


quant_model_urls = _ModelURLs(
{
# fp32 GoogLeNet ported from TensorFlow, with weights quantized in PyTorch
"googlenet_fbgemm": GoogLeNet_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
}
)
13 changes: 13 additions & 0 deletions torchvision/models/quantization/inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,16 @@ def inception_v3(
model.AuxLogits = None

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs
from ..inception import model_urls # noqa: F401


quant_model_urls = _ModelURLs(
{
# fp32 weights ported from TensorFlow, quantized in PyTorch
"inception_v3_google_fbgemm": Inception_V3_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
}
)
12 changes: 12 additions & 0 deletions torchvision/models/quantization/mobilenetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,15 @@ def mobilenet_v2(
model.load_state_dict(weights.get_state_dict(progress=progress))

return model


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs
from ..mobilenetv2 import model_urls # noqa: F401


quant_model_urls = _ModelURLs(
{
"mobilenet_v2_qnnpack": MobileNet_V2_QuantizedWeights.IMAGENET1K_QNNPACK_V1.url,
}
)
12 changes: 12 additions & 0 deletions torchvision/models/quantization/mobilenetv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,15 @@ def mobilenet_v3_large(

inverted_residual_setting, last_channel = _mobilenet_v3_conf("mobilenet_v3_large", **kwargs)
return _mobilenet_v3_model(inverted_residual_setting, last_channel, weights, progress, quantize, **kwargs)


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs
from ..mobilenetv3 import model_urls # noqa: F401


quant_model_urls = _ModelURLs(
{
"mobilenet_v3_large_qnnpack": MobileNet_V3_Large_QuantizedWeights.IMAGENET1K_QNNPACK_V1.url,
}
)
14 changes: 14 additions & 0 deletions torchvision/models/quantization/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,17 @@ def resnext101_64x4d(
_ovewrite_named_param(kwargs, "groups", 64)
_ovewrite_named_param(kwargs, "width_per_group", 4)
return _resnet(QuantizableBottleneck, [3, 4, 23, 3], weights, progress, quantize, **kwargs)


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs
from ..resnet import model_urls # noqa: F401


quant_model_urls = _ModelURLs(
{
"resnet18_fbgemm": ResNet18_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
"resnet50_fbgemm": ResNet50_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
"resnext101_32x8d_fbgemm": ResNeXt101_32X8D_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
}
)
13 changes: 13 additions & 0 deletions torchvision/models/quantization/shufflenetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,16 @@ def shufflenet_v2_x2_0(
return _shufflenetv2(
[4, 8, 4], [24, 244, 488, 976, 2048], weights=weights, progress=progress, quantize=quantize, **kwargs
)


# The dictionary below is internal implementation detail and will be removed in v0.15
from .._utils import _ModelURLs
from ..shufflenetv2 import model_urls # noqa: F401


quant_model_urls = _ModelURLs(
{
"shufflenetv2_x0.5_fbgemm": ShuffleNet_V2_X0_5_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
"shufflenetv2_x1.0_fbgemm": ShuffleNet_V2_X1_0_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
}
)
Loading