From a55369c90e0ca7477a7fe16b8c7bdad32215415c Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Wed, 9 Mar 2022 10:56:42 +0000 Subject: [PATCH 1/3] Standardize messages and switch to NotImplemented exception --- test/test_prototype_models.py | 7 ++----- torchvision/models/convnext.py | 2 +- torchvision/models/detection/faster_rcnn.py | 8 ++++---- torchvision/models/detection/ssd.py | 8 ++++---- torchvision/models/detection/ssdlite.py | 8 ++++---- torchvision/models/efficientnet.py | 2 +- torchvision/models/mnasnet.py | 8 ++++---- torchvision/models/mobilenetv3.py | 2 +- torchvision/models/quantization/mobilenetv3.py | 2 +- torchvision/models/regnet.py | 2 +- torchvision/models/segmentation/_utils.py | 2 +- torchvision/models/shufflenetv2.py | 2 +- torchvision/models/vision_transformer.py | 2 +- 13 files changed, 26 insertions(+), 29 deletions(-) diff --git a/test/test_prototype_models.py b/test/test_prototype_models.py index 6c7234e2ef0..e7cbcd45530 100644 --- a/test/test_prototype_models.py +++ b/test/test_prototype_models.py @@ -43,11 +43,8 @@ def _get_model_weights(model_fn): def _build_model(fn, **kwargs): try: model = fn(**kwargs) - except ValueError as e: - msg = str(e) - if "No checkpoint is available" in msg: - pytest.skip(msg) - raise e + except NotImplemented as e: + pytest.skip(str(e)) return model.eval() diff --git a/torchvision/models/convnext.py b/torchvision/models/convnext.py index 3a0dcdb31cd..5bcec66f601 100644 --- a/torchvision/models/convnext.py +++ b/torchvision/models/convnext.py @@ -197,7 +197,7 @@ def _convnext( model = ConvNeXt(block_setting, stochastic_depth_prob=stochastic_depth_prob, **kwargs) if pretrained: if arch not in _MODELS_URLS: - raise ValueError(f"No checkpoint is available for model type {arch}") + raise NotImplemented(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(_MODELS_URLS[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/detection/faster_rcnn.py b/torchvision/models/detection/faster_rcnn.py index 790740fe9c5..45a90dd06e5 100644 --- a/torchvision/models/detection/faster_rcnn.py +++ b/torchvision/models/detection/faster_rcnn.py @@ -402,7 +402,7 @@ def fasterrcnn_resnet50_fpn( def _fasterrcnn_mobilenet_v3_large_fpn( - weights_name, + arch, pretrained=False, progress=True, num_classes=91, @@ -435,9 +435,9 @@ def _fasterrcnn_mobilenet_v3_large_fpn( backbone, num_classes, rpn_anchor_generator=AnchorGenerator(anchor_sizes, aspect_ratios), **kwargs ) if pretrained: - if model_urls.get(weights_name, None) is None: - raise ValueError(f"No checkpoint is available for model {weights_name}") - state_dict = load_state_dict_from_url(model_urls[weights_name], progress=progress) + if model_urls.get(arch, None) is None: + raise NotImplemented(f"No checkpoint is available for model type {arch}") + state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/detection/ssd.py b/torchvision/models/detection/ssd.py index 08a9ed68e4e..2a943d18b5d 100644 --- a/torchvision/models/detection/ssd.py +++ b/torchvision/models/detection/ssd.py @@ -622,9 +622,9 @@ def ssd300_vgg16( kwargs = {**defaults, **kwargs} model = SSD(backbone, anchor_generator, (300, 300), num_classes, **kwargs) if pretrained: - weights_name = "ssd300_vgg16_coco" - if model_urls.get(weights_name, None) is None: - raise ValueError(f"No checkpoint is available for model {weights_name}") - state_dict = load_state_dict_from_url(model_urls[weights_name], progress=progress) + arch = "ssd300_vgg16_coco" + if model_urls.get(arch, None) is None: + raise NotImplemented(f"No checkpoint is available for model type {arch}") + state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/detection/ssdlite.py b/torchvision/models/detection/ssdlite.py index 1ee59e069ea..bd581586cf2 100644 --- a/torchvision/models/detection/ssdlite.py +++ b/torchvision/models/detection/ssdlite.py @@ -267,9 +267,9 @@ def ssdlite320_mobilenet_v3_large( ) if pretrained: - weights_name = "ssdlite320_mobilenet_v3_large_coco" - if model_urls.get(weights_name, None) is None: - raise ValueError(f"No checkpoint is available for model {weights_name}") - state_dict = load_state_dict_from_url(model_urls[weights_name], progress=progress) + arch = "ssdlite320_mobilenet_v3_large_coco" + if model_urls.get(arch, None) is None: + raise NotImplemented(f"No checkpoint is available for model type {arch}") + state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/efficientnet.py b/torchvision/models/efficientnet.py index f8238912ffd..9d213e747ae 100644 --- a/torchvision/models/efficientnet.py +++ b/torchvision/models/efficientnet.py @@ -373,7 +373,7 @@ def _efficientnet( model = EfficientNet(inverted_residual_setting, dropout, last_channel=last_channel, **kwargs) if pretrained: if model_urls.get(arch, None) is None: - raise ValueError(f"No checkpoint is available for model type {arch}") + raise NotImplemented(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/mnasnet.py b/torchvision/models/mnasnet.py index c3d4013f30c..885e7f78779 100644 --- a/torchvision/models/mnasnet.py +++ b/torchvision/models/mnasnet.py @@ -196,10 +196,10 @@ def _load_from_state_dict( ) -def _load_pretrained(model_name: str, model: nn.Module, progress: bool) -> None: - if model_name not in _MODEL_URLS or _MODEL_URLS[model_name] is None: - raise ValueError(f"No checkpoint is available for model type {model_name}") - checkpoint_url = _MODEL_URLS[model_name] +def _load_pretrained(arch: str, model: nn.Module, progress: bool) -> None: + if arch not in _MODEL_URLS or _MODEL_URLS[arch] is None: + raise NotImplemented(f"No checkpoint is available for model type {arch}") + checkpoint_url = _MODEL_URLS[arch] model.load_state_dict(load_state_dict_from_url(checkpoint_url, progress=progress)) diff --git a/torchvision/models/mobilenetv3.py b/torchvision/models/mobilenetv3.py index 530467d6d53..563834d588b 100644 --- a/torchvision/models/mobilenetv3.py +++ b/torchvision/models/mobilenetv3.py @@ -294,7 +294,7 @@ def _mobilenet_v3( model = MobileNetV3(inverted_residual_setting, last_channel, **kwargs) if pretrained: if model_urls.get(arch, None) is None: - raise ValueError(f"No checkpoint is available for model type {arch}") + raise NotImplemented(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/quantization/mobilenetv3.py b/torchvision/models/quantization/mobilenetv3.py index 4d7e2f7baad..9b9d06ba225 100644 --- a/torchvision/models/quantization/mobilenetv3.py +++ b/torchvision/models/quantization/mobilenetv3.py @@ -114,7 +114,7 @@ def fuse_model(self, is_qat: Optional[bool] = None) -> None: def _load_weights(arch: str, model: QuantizableMobileNetV3, model_url: Optional[str], progress: bool) -> None: if model_url is None: - raise ValueError(f"No checkpoint is available for {arch}") + raise NotImplemented(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_url, progress=progress) model.load_state_dict(state_dict) diff --git a/torchvision/models/regnet.py b/torchvision/models/regnet.py index 74abd20b237..63aee4a0c78 100644 --- a/torchvision/models/regnet.py +++ b/torchvision/models/regnet.py @@ -395,7 +395,7 @@ def _regnet(arch: str, block_params: BlockParams, pretrained: bool, progress: bo model = RegNet(block_params, norm_layer=norm_layer, **kwargs) if pretrained: if arch not in model_urls: - raise ValueError(f"No checkpoint is available for model type {arch}") + raise NotImplemented(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/segmentation/_utils.py b/torchvision/models/segmentation/_utils.py index 0bbea5d3e81..aa89c2fb878 100644 --- a/torchvision/models/segmentation/_utils.py +++ b/torchvision/models/segmentation/_utils.py @@ -40,6 +40,6 @@ def forward(self, x: Tensor) -> Dict[str, Tensor]: def _load_weights(arch: str, model: nn.Module, model_url: Optional[str], progress: bool) -> None: if model_url is None: - raise ValueError(f"No checkpoint is available for {arch}") + raise NotImplemented(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_url, progress=progress) model.load_state_dict(state_dict) diff --git a/torchvision/models/shufflenetv2.py b/torchvision/models/shufflenetv2.py index f3758c54aaf..8ad07c53c54 100644 --- a/torchvision/models/shufflenetv2.py +++ b/torchvision/models/shufflenetv2.py @@ -162,7 +162,7 @@ def _shufflenetv2(arch: str, pretrained: bool, progress: bool, *args: Any, **kwa if pretrained: model_url = model_urls[arch] if model_url is None: - raise ValueError(f"No checkpoint is available for model type {arch}") + raise NotImplemented(f"No checkpoint is available for model type {arch}") else: state_dict = load_state_dict_from_url(model_url, progress=progress) model.load_state_dict(state_dict) diff --git a/torchvision/models/vision_transformer.py b/torchvision/models/vision_transformer.py index 29f756ccbe5..c85971bc5b9 100644 --- a/torchvision/models/vision_transformer.py +++ b/torchvision/models/vision_transformer.py @@ -298,7 +298,7 @@ def _vision_transformer( if pretrained: if arch not in model_urls: - raise ValueError(f"No checkpoint is available for model type '{arch}'!") + raise NotImplemented(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) From 5159011185dc5b231efe5fb276132dd3f30f4e9e Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Wed, 9 Mar 2022 11:02:57 +0000 Subject: [PATCH 2/3] Switch to NotImplementedError. --- test/test_prototype_models.py | 2 +- torchvision/models/convnext.py | 2 +- torchvision/models/detection/faster_rcnn.py | 2 +- torchvision/models/detection/ssd.py | 2 +- torchvision/models/detection/ssdlite.py | 2 +- torchvision/models/efficientnet.py | 2 +- torchvision/models/mnasnet.py | 2 +- torchvision/models/mobilenetv3.py | 2 +- torchvision/models/quantization/mobilenetv3.py | 2 +- torchvision/models/regnet.py | 2 +- torchvision/models/segmentation/_utils.py | 2 +- torchvision/models/shufflenetv2.py | 2 +- torchvision/models/vision_transformer.py | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/test_prototype_models.py b/test/test_prototype_models.py index e7cbcd45530..21bc26503d5 100644 --- a/test/test_prototype_models.py +++ b/test/test_prototype_models.py @@ -43,7 +43,7 @@ def _get_model_weights(model_fn): def _build_model(fn, **kwargs): try: model = fn(**kwargs) - except NotImplemented as e: + except NotImplementedError as e: pytest.skip(str(e)) return model.eval() diff --git a/torchvision/models/convnext.py b/torchvision/models/convnext.py index 5bcec66f601..76f51592c5e 100644 --- a/torchvision/models/convnext.py +++ b/torchvision/models/convnext.py @@ -197,7 +197,7 @@ def _convnext( model = ConvNeXt(block_setting, stochastic_depth_prob=stochastic_depth_prob, **kwargs) if pretrained: if arch not in _MODELS_URLS: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(_MODELS_URLS[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/detection/faster_rcnn.py b/torchvision/models/detection/faster_rcnn.py index 45a90dd06e5..4bb5d16e675 100644 --- a/torchvision/models/detection/faster_rcnn.py +++ b/torchvision/models/detection/faster_rcnn.py @@ -436,7 +436,7 @@ def _fasterrcnn_mobilenet_v3_large_fpn( ) if pretrained: if model_urls.get(arch, None) is None: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/detection/ssd.py b/torchvision/models/detection/ssd.py index 2a943d18b5d..47f41615b84 100644 --- a/torchvision/models/detection/ssd.py +++ b/torchvision/models/detection/ssd.py @@ -624,7 +624,7 @@ def ssd300_vgg16( if pretrained: arch = "ssd300_vgg16_coco" if model_urls.get(arch, None) is None: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/detection/ssdlite.py b/torchvision/models/detection/ssdlite.py index bd581586cf2..19a62778bf7 100644 --- a/torchvision/models/detection/ssdlite.py +++ b/torchvision/models/detection/ssdlite.py @@ -269,7 +269,7 @@ def ssdlite320_mobilenet_v3_large( if pretrained: arch = "ssdlite320_mobilenet_v3_large_coco" if model_urls.get(arch, None) is None: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/efficientnet.py b/torchvision/models/efficientnet.py index 9d213e747ae..550616b1032 100644 --- a/torchvision/models/efficientnet.py +++ b/torchvision/models/efficientnet.py @@ -373,7 +373,7 @@ def _efficientnet( model = EfficientNet(inverted_residual_setting, dropout, last_channel=last_channel, **kwargs) if pretrained: if model_urls.get(arch, None) is None: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/mnasnet.py b/torchvision/models/mnasnet.py index 885e7f78779..b9544374a88 100644 --- a/torchvision/models/mnasnet.py +++ b/torchvision/models/mnasnet.py @@ -198,7 +198,7 @@ def _load_from_state_dict( def _load_pretrained(arch: str, model: nn.Module, progress: bool) -> None: if arch not in _MODEL_URLS or _MODEL_URLS[arch] is None: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") checkpoint_url = _MODEL_URLS[arch] model.load_state_dict(load_state_dict_from_url(checkpoint_url, progress=progress)) diff --git a/torchvision/models/mobilenetv3.py b/torchvision/models/mobilenetv3.py index 563834d588b..ccc11e85768 100644 --- a/torchvision/models/mobilenetv3.py +++ b/torchvision/models/mobilenetv3.py @@ -294,7 +294,7 @@ def _mobilenet_v3( model = MobileNetV3(inverted_residual_setting, last_channel, **kwargs) if pretrained: if model_urls.get(arch, None) is None: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/quantization/mobilenetv3.py b/torchvision/models/quantization/mobilenetv3.py index 9b9d06ba225..068aa841d23 100644 --- a/torchvision/models/quantization/mobilenetv3.py +++ b/torchvision/models/quantization/mobilenetv3.py @@ -114,7 +114,7 @@ def fuse_model(self, is_qat: Optional[bool] = None) -> None: def _load_weights(arch: str, model: QuantizableMobileNetV3, model_url: Optional[str], progress: bool) -> None: if model_url is None: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_url, progress=progress) model.load_state_dict(state_dict) diff --git a/torchvision/models/regnet.py b/torchvision/models/regnet.py index 63aee4a0c78..d6248be6ebb 100644 --- a/torchvision/models/regnet.py +++ b/torchvision/models/regnet.py @@ -395,7 +395,7 @@ def _regnet(arch: str, block_params: BlockParams, pretrained: bool, progress: bo model = RegNet(block_params, norm_layer=norm_layer, **kwargs) if pretrained: if arch not in model_urls: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/segmentation/_utils.py b/torchvision/models/segmentation/_utils.py index aa89c2fb878..11e3356f2bd 100644 --- a/torchvision/models/segmentation/_utils.py +++ b/torchvision/models/segmentation/_utils.py @@ -40,6 +40,6 @@ def forward(self, x: Tensor) -> Dict[str, Tensor]: def _load_weights(arch: str, model: nn.Module, model_url: Optional[str], progress: bool) -> None: if model_url is None: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_url, progress=progress) model.load_state_dict(state_dict) diff --git a/torchvision/models/shufflenetv2.py b/torchvision/models/shufflenetv2.py index 8ad07c53c54..cf894496706 100644 --- a/torchvision/models/shufflenetv2.py +++ b/torchvision/models/shufflenetv2.py @@ -162,7 +162,7 @@ def _shufflenetv2(arch: str, pretrained: bool, progress: bool, *args: Any, **kwa if pretrained: model_url = model_urls[arch] if model_url is None: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") else: state_dict = load_state_dict_from_url(model_url, progress=progress) model.load_state_dict(state_dict) diff --git a/torchvision/models/vision_transformer.py b/torchvision/models/vision_transformer.py index c85971bc5b9..71d0af411f4 100644 --- a/torchvision/models/vision_transformer.py +++ b/torchvision/models/vision_transformer.py @@ -298,7 +298,7 @@ def _vision_transformer( if pretrained: if arch not in model_urls: - raise NotImplemented(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No checkpoint is available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) From 394aa03aee1c485f134ee89351ea3cdbd0e8fc40 Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Wed, 9 Mar 2022 13:19:37 +0000 Subject: [PATCH 3/3] Update error messages --- torchvision/models/convnext.py | 2 +- torchvision/models/detection/faster_rcnn.py | 2 +- torchvision/models/detection/ssd.py | 2 +- torchvision/models/detection/ssdlite.py | 2 +- torchvision/models/efficientnet.py | 2 +- torchvision/models/mnasnet.py | 2 +- torchvision/models/mobilenetv3.py | 2 +- torchvision/models/quantization/mobilenetv3.py | 2 +- torchvision/models/regnet.py | 2 +- torchvision/models/segmentation/_utils.py | 2 +- torchvision/models/shufflenetv2.py | 2 +- torchvision/models/vision_transformer.py | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/torchvision/models/convnext.py b/torchvision/models/convnext.py index 76f51592c5e..4976219dbc8 100644 --- a/torchvision/models/convnext.py +++ b/torchvision/models/convnext.py @@ -197,7 +197,7 @@ def _convnext( model = ConvNeXt(block_setting, stochastic_depth_prob=stochastic_depth_prob, **kwargs) if pretrained: if arch not in _MODELS_URLS: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") state_dict = load_state_dict_from_url(_MODELS_URLS[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/detection/faster_rcnn.py b/torchvision/models/detection/faster_rcnn.py index 4bb5d16e675..3cad1f24f21 100644 --- a/torchvision/models/detection/faster_rcnn.py +++ b/torchvision/models/detection/faster_rcnn.py @@ -436,7 +436,7 @@ def _fasterrcnn_mobilenet_v3_large_fpn( ) if pretrained: if model_urls.get(arch, None) is None: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/detection/ssd.py b/torchvision/models/detection/ssd.py index 47f41615b84..b1c96c37571 100644 --- a/torchvision/models/detection/ssd.py +++ b/torchvision/models/detection/ssd.py @@ -624,7 +624,7 @@ def ssd300_vgg16( if pretrained: arch = "ssd300_vgg16_coco" if model_urls.get(arch, None) is None: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/detection/ssdlite.py b/torchvision/models/detection/ssdlite.py index 19a62778bf7..b0754cce13a 100644 --- a/torchvision/models/detection/ssdlite.py +++ b/torchvision/models/detection/ssdlite.py @@ -269,7 +269,7 @@ def ssdlite320_mobilenet_v3_large( if pretrained: arch = "ssdlite320_mobilenet_v3_large_coco" if model_urls.get(arch, None) is None: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/efficientnet.py b/torchvision/models/efficientnet.py index 550616b1032..0a995037916 100644 --- a/torchvision/models/efficientnet.py +++ b/torchvision/models/efficientnet.py @@ -373,7 +373,7 @@ def _efficientnet( model = EfficientNet(inverted_residual_setting, dropout, last_channel=last_channel, **kwargs) if pretrained: if model_urls.get(arch, None) is None: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/mnasnet.py b/torchvision/models/mnasnet.py index b9544374a88..2b735804648 100644 --- a/torchvision/models/mnasnet.py +++ b/torchvision/models/mnasnet.py @@ -198,7 +198,7 @@ def _load_from_state_dict( def _load_pretrained(arch: str, model: nn.Module, progress: bool) -> None: if arch not in _MODEL_URLS or _MODEL_URLS[arch] is None: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") checkpoint_url = _MODEL_URLS[arch] model.load_state_dict(load_state_dict_from_url(checkpoint_url, progress=progress)) diff --git a/torchvision/models/mobilenetv3.py b/torchvision/models/mobilenetv3.py index ccc11e85768..11e4c88b2e6 100644 --- a/torchvision/models/mobilenetv3.py +++ b/torchvision/models/mobilenetv3.py @@ -294,7 +294,7 @@ def _mobilenet_v3( model = MobileNetV3(inverted_residual_setting, last_channel, **kwargs) if pretrained: if model_urls.get(arch, None) is None: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/quantization/mobilenetv3.py b/torchvision/models/quantization/mobilenetv3.py index 068aa841d23..9c1d23a2c12 100644 --- a/torchvision/models/quantization/mobilenetv3.py +++ b/torchvision/models/quantization/mobilenetv3.py @@ -114,7 +114,7 @@ def fuse_model(self, is_qat: Optional[bool] = None) -> None: def _load_weights(arch: str, model: QuantizableMobileNetV3, model_url: Optional[str], progress: bool) -> None: if model_url is None: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") state_dict = load_state_dict_from_url(model_url, progress=progress) model.load_state_dict(state_dict) diff --git a/torchvision/models/regnet.py b/torchvision/models/regnet.py index d6248be6ebb..43fb6ce616e 100644 --- a/torchvision/models/regnet.py +++ b/torchvision/models/regnet.py @@ -395,7 +395,7 @@ def _regnet(arch: str, block_params: BlockParams, pretrained: bool, progress: bo model = RegNet(block_params, norm_layer=norm_layer, **kwargs) if pretrained: if arch not in model_urls: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict) return model diff --git a/torchvision/models/segmentation/_utils.py b/torchvision/models/segmentation/_utils.py index 11e3356f2bd..c3537ddeb67 100644 --- a/torchvision/models/segmentation/_utils.py +++ b/torchvision/models/segmentation/_utils.py @@ -40,6 +40,6 @@ def forward(self, x: Tensor) -> Dict[str, Tensor]: def _load_weights(arch: str, model: nn.Module, model_url: Optional[str], progress: bool) -> None: if model_url is None: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") state_dict = load_state_dict_from_url(model_url, progress=progress) model.load_state_dict(state_dict) diff --git a/torchvision/models/shufflenetv2.py b/torchvision/models/shufflenetv2.py index cf894496706..155f426c82c 100644 --- a/torchvision/models/shufflenetv2.py +++ b/torchvision/models/shufflenetv2.py @@ -162,7 +162,7 @@ def _shufflenetv2(arch: str, pretrained: bool, progress: bool, *args: Any, **kwa if pretrained: model_url = model_urls[arch] if model_url is None: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") else: state_dict = load_state_dict_from_url(model_url, progress=progress) model.load_state_dict(state_dict) diff --git a/torchvision/models/vision_transformer.py b/torchvision/models/vision_transformer.py index 71d0af411f4..748495d993e 100644 --- a/torchvision/models/vision_transformer.py +++ b/torchvision/models/vision_transformer.py @@ -298,7 +298,7 @@ def _vision_transformer( if pretrained: if arch not in model_urls: - raise NotImplementedError(f"No checkpoint is available for model type {arch}") + raise NotImplementedError(f"No pre-trained weights are available for model type {arch}") state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) model.load_state_dict(state_dict)