Skip to content

Commit 6bbcae6

Browse files
NicolasHugfacebook-github-bot
authored andcommitted
[fbsync] Reinstate and deprecate model_urls and quant_model_urls (#5992)
Summary: * Reinstate and deprecate `model_urls` and `quant_model_urls` * Apply suggestions from code review * Move todo location * Add alexnet * Add densenet * Add efficientnet * Add googlenet. * Add inception. * Add mobilenetv3 * Add regnet * Add resnet * Add shufflenetv2 * Fix linter * Add squeezenet * Add vgg * Add vit * Add quantized googlenet * Add quantized inceptionv3 * Add quantized mobilenet_v3 * Add quantized resnet * Add quantized shufflenetv2 * Fix incorrect imports * Add faster_rcnn * Add fcos * Add keypoint rcnn * Add mask rcnn * Add retinanet * Add ssd * Add ssdlite * Add deeplabv3 * Add fcn * Add lraspp. * Add video resnet * Removing weights for shufflenetv2_x1.5 and shufflenetv2_x2.0 * Update the comments Reviewed By: datumbox Differential Revision: D36413362 fbshipit-source-id: 56d6855a77e17db457542cb1c12373a1a881b46b Co-authored-by: Nicolas Hug <[email protected]> Co-authored-by: Nicolas Hug <[email protected]>
1 parent c476de2 commit 6bbcae6

31 files changed

+426
-3
lines changed

torchvision/models/_utils.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def wrapper(*args: Any, **kwargs: Any) -> D:
134134
keyword_only_kwargs = dict(zip(keyword_only_params, keyword_only_args))
135135
warnings.warn(
136136
f"Using {sequence_to_str(tuple(keyword_only_kwargs.keys()), separate_last='and ')} as positional "
137-
f"parameter(s) is deprecated. Please use keyword parameter(s) instead."
137+
f"parameter(s) is deprecated since 0.13 and will be removed in 0.15. Please use keyword parameter(s) "
138+
f"instead."
138139
)
139140
kwargs.update(keyword_only_kwargs)
140141

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

206207
if not pretrained_positional:
207208
warnings.warn(
208-
f"The parameter '{pretrained_param}' is deprecated, please use '{weights_param}' instead."
209+
f"The parameter '{pretrained_param}' is deprecated since 0.13 and will be removed in 0.15, "
210+
f"please use '{weights_param}' instead."
209211
)
210212

211213
msg = (
212-
f"Arguments other than a weight enum or `None` for '{weights_param}' are deprecated. "
214+
f"Arguments other than a weight enum or `None` for '{weights_param}' are deprecated since 0.13 and "
215+
f"will be removed in 0.15. "
213216
f"The current behavior is equivalent to passing `{weights_param}={default_weights_arg}`."
214217
)
215218
if pretrained_arg:
@@ -242,3 +245,12 @@ def _ovewrite_value_param(param: Optional[V], new_value: V) -> V:
242245
if param != new_value:
243246
raise ValueError(f"The parameter '{param}' expected value {new_value} but got {param} instead.")
244247
return new_value
248+
249+
250+
class _ModelURLs(dict):
251+
def __getitem__(self, item):
252+
warnings.warn(
253+
"Accessing the model URLs via the internal dictionary of the module is deprecated since 0.13 and will "
254+
"be removed in 0.15. Please access them via the appropriate Weights Enum instead."
255+
)
256+
return super().__getitem__(item)

torchvision/models/alexnet.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,14 @@ def alexnet(*, weights: Optional[AlexNet_Weights] = None, progress: bool = True,
111111
model.load_state_dict(weights.get_state_dict(progress=progress))
112112

113113
return model
114+
115+
116+
# The dictionary below is internal implementation detail and will be removed in v0.15
117+
from ._utils import _ModelURLs
118+
119+
120+
model_urls = _ModelURLs(
121+
{
122+
"alexnet": AlexNet_Weights.IMAGENET1K_V1.url,
123+
}
124+
)

torchvision/models/densenet.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,17 @@ def densenet201(*, weights: Optional[DenseNet201_Weights] = None, progress: bool
430430
weights = DenseNet201_Weights.verify(weights)
431431

432432
return _densenet(32, (6, 12, 48, 32), 64, weights, progress, **kwargs)
433+
434+
435+
# The dictionary below is internal implementation detail and will be removed in v0.15
436+
from ._utils import _ModelURLs
437+
438+
439+
model_urls = _ModelURLs(
440+
{
441+
"densenet121": DenseNet121_Weights.IMAGENET1K_V1.url,
442+
"densenet169": DenseNet169_Weights.IMAGENET1K_V1.url,
443+
"densenet201": DenseNet201_Weights.IMAGENET1K_V1.url,
444+
"densenet161": DenseNet161_Weights.IMAGENET1K_V1.url,
445+
}
446+
)

torchvision/models/detection/faster_rcnn.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,3 +804,16 @@ def fasterrcnn_mobilenet_v3_large_fpn(
804804
trainable_backbone_layers=trainable_backbone_layers,
805805
**kwargs,
806806
)
807+
808+
809+
# The dictionary below is internal implementation detail and will be removed in v0.15
810+
from .._utils import _ModelURLs
811+
812+
813+
model_urls = _ModelURLs(
814+
{
815+
"fasterrcnn_resnet50_fpn_coco": FasterRCNN_ResNet50_FPN_Weights.COCO_V1.url,
816+
"fasterrcnn_mobilenet_v3_large_320_fpn_coco": FasterRCNN_MobileNet_V3_Large_320_FPN_Weights.COCO_V1.url,
817+
"fasterrcnn_mobilenet_v3_large_fpn_coco": FasterRCNN_MobileNet_V3_Large_FPN_Weights.COCO_V1.url,
818+
}
819+
)

torchvision/models/detection/fcos.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,3 +758,14 @@ def fcos_resnet50_fpn(
758758
model.load_state_dict(weights.get_state_dict(progress=progress))
759759

760760
return model
761+
762+
763+
# The dictionary below is internal implementation detail and will be removed in v0.15
764+
from .._utils import _ModelURLs
765+
766+
767+
model_urls = _ModelURLs(
768+
{
769+
"fcos_resnet50_fpn_coco": FCOS_ResNet50_FPN_Weights.COCO_V1.url,
770+
}
771+
)

torchvision/models/detection/keypoint_rcnn.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,16 @@ def keypointrcnn_resnet50_fpn(
454454
overwrite_eps(model, 0.0)
455455

456456
return model
457+
458+
459+
# The dictionary below is internal implementation detail and will be removed in v0.15
460+
from .._utils import _ModelURLs
461+
462+
463+
model_urls = _ModelURLs(
464+
{
465+
# legacy model for BC reasons, see https://github.com/pytorch/vision/issues/1606
466+
"keypointrcnn_resnet50_fpn_coco_legacy": KeypointRCNN_ResNet50_FPN_Weights.COCO_LEGACY.url,
467+
"keypointrcnn_resnet50_fpn_coco": KeypointRCNN_ResNet50_FPN_Weights.COCO_V1.url,
468+
}
469+
)

torchvision/models/detection/mask_rcnn.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,14 @@ def maskrcnn_resnet50_fpn_v2(
565565
model.load_state_dict(weights.get_state_dict(progress=progress))
566566

567567
return model
568+
569+
570+
# The dictionary below is internal implementation detail and will be removed in v0.15
571+
from .._utils import _ModelURLs
572+
573+
574+
model_urls = _ModelURLs(
575+
{
576+
"maskrcnn_resnet50_fpn_coco": MaskRCNN_ResNet50_FPN_Weights.COCO_V1.url,
577+
}
578+
)

torchvision/models/detection/retinanet.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,3 +879,14 @@ def retinanet_resnet50_fpn_v2(
879879
model.load_state_dict(weights.get_state_dict(progress=progress))
880880

881881
return model
882+
883+
884+
# The dictionary below is internal implementation detail and will be removed in v0.15
885+
from .._utils import _ModelURLs
886+
887+
888+
model_urls = _ModelURLs(
889+
{
890+
"retinanet_resnet50_fpn_coco": RetinaNet_ResNet50_FPN_Weights.COCO_V1.url,
891+
}
892+
)

torchvision/models/detection/ssd.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,3 +672,25 @@ def ssd300_vgg16(
672672
model.load_state_dict(weights.get_state_dict(progress=progress))
673673

674674
return model
675+
676+
677+
# The dictionary below is internal implementation detail and will be removed in v0.15
678+
from .._utils import _ModelURLs
679+
680+
681+
model_urls = _ModelURLs(
682+
{
683+
"ssd300_vgg16_coco": SSD300_VGG16_Weights.COCO_V1.url,
684+
}
685+
)
686+
687+
688+
backbone_urls = _ModelURLs(
689+
{
690+
# We port the features of a VGG16 backbone trained by amdegroot because unlike the one on TorchVision, it uses
691+
# the same input standardization method as the paper.
692+
# Ref: https://s3.amazonaws.com/amdegroot-models/vgg16_reducedfc.pth
693+
# Only the `features` weights have proper values, those on the `classifier` module are filled with nans.
694+
"vgg16_features": VGG16_Weights.IMAGENET1K_FEATURES.url,
695+
}
696+
)

torchvision/models/detection/ssdlite.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,14 @@ def ssdlite320_mobilenet_v3_large(
321321
model.load_state_dict(weights.get_state_dict(progress=progress))
322322

323323
return model
324+
325+
326+
# The dictionary below is internal implementation detail and will be removed in v0.15
327+
from .._utils import _ModelURLs
328+
329+
330+
model_urls = _ModelURLs(
331+
{
332+
"ssdlite320_mobilenet_v3_large_coco": SSDLite320_MobileNet_V3_Large_Weights.COCO_V1.url,
333+
}
334+
)

torchvision/models/efficientnet.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,3 +1028,23 @@ def efficientnet_v2_l(
10281028
norm_layer=partial(nn.BatchNorm2d, eps=1e-03),
10291029
**kwargs,
10301030
)
1031+
1032+
1033+
# The dictionary below is internal implementation detail and will be removed in v0.15
1034+
from ._utils import _ModelURLs
1035+
1036+
1037+
model_urls = _ModelURLs(
1038+
{
1039+
# Weights ported from https://github.com/rwightman/pytorch-image-models/
1040+
"efficientnet_b0": EfficientNet_B0_Weights.IMAGENET1K_V1.url,
1041+
"efficientnet_b1": EfficientNet_B1_Weights.IMAGENET1K_V1.url,
1042+
"efficientnet_b2": EfficientNet_B2_Weights.IMAGENET1K_V1.url,
1043+
"efficientnet_b3": EfficientNet_B3_Weights.IMAGENET1K_V1.url,
1044+
"efficientnet_b4": EfficientNet_B4_Weights.IMAGENET1K_V1.url,
1045+
# Weights ported from https://github.com/lukemelas/EfficientNet-PyTorch/
1046+
"efficientnet_b5": EfficientNet_B5_Weights.IMAGENET1K_V1.url,
1047+
"efficientnet_b6": EfficientNet_B6_Weights.IMAGENET1K_V1.url,
1048+
"efficientnet_b7": EfficientNet_B7_Weights.IMAGENET1K_V1.url,
1049+
}
1050+
)

torchvision/models/googlenet.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,15 @@ def googlenet(*, weights: Optional[GoogLeNet_Weights] = None, progress: bool = T
339339
)
340340

341341
return model
342+
343+
344+
# The dictionary below is internal implementation detail and will be removed in v0.15
345+
from ._utils import _ModelURLs
346+
347+
348+
model_urls = _ModelURLs(
349+
{
350+
# GoogLeNet ported from TensorFlow
351+
"googlenet": GoogLeNet_Weights.IMAGENET1K_V1.url,
352+
}
353+
)

torchvision/models/inception.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,15 @@ def inception_v3(*, weights: Optional[Inception_V3_Weights] = None, progress: bo
471471
model.AuxLogits = None
472472

473473
return model
474+
475+
476+
# The dictionary below is internal implementation detail and will be removed in v0.15
477+
from ._utils import _ModelURLs
478+
479+
480+
model_urls = _ModelURLs(
481+
{
482+
# Inception v3 ported from TensorFlow
483+
"inception_v3_google": Inception_V3_Weights.IMAGENET1K_V1.url,
484+
}
485+
)

torchvision/models/mobilenetv2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,14 @@ def mobilenet_v2(
263263
model.load_state_dict(weights.get_state_dict(progress=progress))
264264

265265
return model
266+
267+
268+
# The dictionary below is internal implementation detail and will be removed in v0.15
269+
from ._utils import _ModelURLs
270+
271+
272+
model_urls = _ModelURLs(
273+
{
274+
"mobilenet_v2": MobileNet_V2_Weights.IMAGENET1K_V1.url,
275+
}
276+
)

torchvision/models/mobilenetv3.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,15 @@ def mobilenet_v3_small(
414414

415415
inverted_residual_setting, last_channel = _mobilenet_v3_conf("mobilenet_v3_small", **kwargs)
416416
return _mobilenet_v3(inverted_residual_setting, last_channel, weights, progress, **kwargs)
417+
418+
419+
# The dictionary below is internal implementation detail and will be removed in v0.15
420+
from ._utils import _ModelURLs
421+
422+
423+
model_urls = _ModelURLs(
424+
{
425+
"mobilenet_v3_large": MobileNet_V3_Large_Weights.IMAGENET1K_V1.url,
426+
"mobilenet_v3_small": MobileNet_V3_Small_Weights.IMAGENET1K_V1.url,
427+
}
428+
)

torchvision/models/quantization/googlenet.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,16 @@ def googlenet(
200200
)
201201

202202
return model
203+
204+
205+
# The dictionary below is internal implementation detail and will be removed in v0.15
206+
from .._utils import _ModelURLs
207+
from ..googlenet import model_urls # noqa: F401
208+
209+
210+
quant_model_urls = _ModelURLs(
211+
{
212+
# fp32 GoogLeNet ported from TensorFlow, with weights quantized in PyTorch
213+
"googlenet_fbgemm": GoogLeNet_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
214+
}
215+
)

torchvision/models/quantization/inception.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,16 @@ def inception_v3(
251251
model.AuxLogits = None
252252

253253
return model
254+
255+
256+
# The dictionary below is internal implementation detail and will be removed in v0.15
257+
from .._utils import _ModelURLs
258+
from ..inception import model_urls # noqa: F401
259+
260+
261+
quant_model_urls = _ModelURLs(
262+
{
263+
# fp32 weights ported from TensorFlow, quantized in PyTorch
264+
"inception_v3_google_fbgemm": Inception_V3_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
265+
}
266+
)

torchvision/models/quantization/mobilenetv2.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,15 @@ def mobilenet_v2(
131131
model.load_state_dict(weights.get_state_dict(progress=progress))
132132

133133
return model
134+
135+
136+
# The dictionary below is internal implementation detail and will be removed in v0.15
137+
from .._utils import _ModelURLs
138+
from ..mobilenetv2 import model_urls # noqa: F401
139+
140+
141+
quant_model_urls = _ModelURLs(
142+
{
143+
"mobilenet_v2_qnnpack": MobileNet_V2_QuantizedWeights.IMAGENET1K_QNNPACK_V1.url,
144+
}
145+
)

torchvision/models/quantization/mobilenetv3.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,15 @@ def mobilenet_v3_large(
211211

212212
inverted_residual_setting, last_channel = _mobilenet_v3_conf("mobilenet_v3_large", **kwargs)
213213
return _mobilenet_v3_model(inverted_residual_setting, last_channel, weights, progress, quantize, **kwargs)
214+
215+
216+
# The dictionary below is internal implementation detail and will be removed in v0.15
217+
from .._utils import _ModelURLs
218+
from ..mobilenetv3 import model_urls # noqa: F401
219+
220+
221+
quant_model_urls = _ModelURLs(
222+
{
223+
"mobilenet_v3_large_qnnpack": MobileNet_V3_Large_QuantizedWeights.IMAGENET1K_QNNPACK_V1.url,
224+
}
225+
)

torchvision/models/quantization/resnet.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,17 @@ def resnext101_64x4d(
362362
_ovewrite_named_param(kwargs, "groups", 64)
363363
_ovewrite_named_param(kwargs, "width_per_group", 4)
364364
return _resnet(QuantizableBottleneck, [3, 4, 23, 3], weights, progress, quantize, **kwargs)
365+
366+
367+
# The dictionary below is internal implementation detail and will be removed in v0.15
368+
from .._utils import _ModelURLs
369+
from ..resnet import model_urls # noqa: F401
370+
371+
372+
quant_model_urls = _ModelURLs(
373+
{
374+
"resnet18_fbgemm": ResNet18_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
375+
"resnet50_fbgemm": ResNet50_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
376+
"resnext101_32x8d_fbgemm": ResNeXt101_32X8D_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
377+
}
378+
)

torchvision/models/quantization/shufflenetv2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,16 @@ def shufflenet_v2_x2_0(
298298
return _shufflenetv2(
299299
[4, 8, 4], [24, 244, 488, 976, 2048], weights=weights, progress=progress, quantize=quantize, **kwargs
300300
)
301+
302+
303+
# The dictionary below is internal implementation detail and will be removed in v0.15
304+
from .._utils import _ModelURLs
305+
from ..shufflenetv2 import model_urls # noqa: F401
306+
307+
308+
quant_model_urls = _ModelURLs(
309+
{
310+
"shufflenetv2_x0.5_fbgemm": ShuffleNet_V2_X0_5_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
311+
"shufflenetv2_x1.0_fbgemm": ShuffleNet_V2_X1_0_QuantizedWeights.IMAGENET1K_FBGEMM_V1.url,
312+
}
313+
)

0 commit comments

Comments
 (0)