Skip to content

Commit e722e9c

Browse files
datumboxNicolasHug
andauthored
Reinstate and deprecate model_urls and quant_model_urls (#5992)
* Reinstate and deprecate `model_urls` and `quant_model_urls` * Apply suggestions from code review Co-authored-by: Nicolas Hug <[email protected]> * 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 Co-authored-by: Nicolas Hug <[email protected]>
1 parent 9166b67 commit e722e9c

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+
)

0 commit comments

Comments
 (0)