diff --git a/test/test_backbone_utils.py b/test/test_backbone_utils.py index a2b2406441e..0c8ae971929 100644 --- a/test/test_backbone_utils.py +++ b/test/test_backbone_utils.py @@ -16,7 +16,11 @@ def get_available_models(): return [ k for k, v in models.__dict__.items() - if callable(v) and k[0].lower() == k[0] and k[0] != "_" and k != "get_weight" + if callable(v) + and k[0].lower() == k[0] + and k[0] != "_" + and k != "get_weight" + and not k.startswith("enable_beta") ] diff --git a/test/test_models.py b/test/test_models.py index 0acef4dcef6..dcf11d2ce04 100644 --- a/test/test_models.py +++ b/test/test_models.py @@ -26,7 +26,11 @@ def get_models_from_module(module): return [ v for k, v in module.__dict__.items() - if callable(v) and k[0].lower() == k[0] and k[0] != "_" and k != "get_weight" + if callable(v) + and k[0].lower() == k[0] + and k[0] != "_" + and k != "get_weight" + and not k.startswith("enable_beta") ] diff --git a/torchvision/io/__init__.py b/torchvision/io/__init__.py index 22788cef71e..7a117f011a3 100644 --- a/torchvision/io/__init__.py +++ b/torchvision/io/__init__.py @@ -40,6 +40,14 @@ from .video_reader import VideoReader +_BETA_VIDEO_API_IS_ENABLED = False + + +def enable_beta_video_api(): + global _BETA_VIDEO_API_IS_ENABLED + _BETA_VIDEO_API_IS_ENABLED = True + + __all__ = [ "write_video", "read_video", diff --git a/torchvision/io/video_reader.py b/torchvision/io/video_reader.py index 881b9d75bd4..bfa326bbda3 100644 --- a/torchvision/io/video_reader.py +++ b/torchvision/io/video_reader.py @@ -1,3 +1,4 @@ +import warnings from typing import Any, Dict, Iterator import torch @@ -92,6 +93,16 @@ class VideoReader: def __init__(self, path: str, stream: str = "video", num_threads: int = 0, device: str = "cpu") -> None: _log_api_usage_once(self) + from . import _BETA_VIDEO_API_IS_ENABLED # import here to avoid circular import + + if not _BETA_VIDEO_API_IS_ENABLED: + warnings.warn( + "The VideoReader class is still in Beta stage, which means " + "that backward compatibility isn't fully guaranteed. " + "Please visit to learn more about what we are planning to change in future versions. " + "To silence this warning, please call torchvision.io.enable_beta_video_api." + ) + self.is_cuda = False device = torch.device(device) if device.type == "cuda": diff --git a/torchvision/models/__init__.py b/torchvision/models/__init__.py index 00b5ebefe55..35526a56526 100644 --- a/torchvision/models/__init__.py +++ b/torchvision/models/__init__.py @@ -1,3 +1,5 @@ +import importlib + from .alexnet import * from .convnext import * from .densenet import * @@ -13,9 +15,23 @@ from .vgg import * from .vision_transformer import * from .swin_transformer import * -from . import detection from . import optical_flow from . import quantization from . import segmentation from . import video from ._api import get_weight + + +def __getattr__(name): + if name == "detection": + return importlib.import_module("." + name, __name__) + else: + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + + +_BETA_DETECTION_IS_ENABLED = False + + +def enable_beta_detection(): + global _BETA_DETECTION_IS_ENABLED + _BETA_DETECTION_IS_ENABLED = True diff --git a/torchvision/models/detection/__init__.py b/torchvision/models/detection/__init__.py index 4146651c737..909fc62face 100644 --- a/torchvision/models/detection/__init__.py +++ b/torchvision/models/detection/__init__.py @@ -5,3 +5,15 @@ from .retinanet import * from .ssd import * from .ssdlite import * + +import warnings + +from .. import _BETA_DETECTION_IS_ENABLED + +if not _BETA_DETECTION_IS_ENABLED: + warnings.warn( + "The torchvision.models.detection module is still in Beta stage, which means " + "that backward compatibility isn't fully guaranteed. " + "Please visit to learn more about what we are planning to change in future versions. " + "To silence this warning, please call torchvision.models.enable_beta_detection." + )