-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[WIP] Add remove-able warnings for Beta modules or functions #6173
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we mark the whole class as Beta. A warning is raised unless Functions could be treated similarly. We could have a more general decorator if needed. |
||
warnings.warn( | ||
"The VideoReader class is still in Beta stage, which means " | ||
"that backward compatibility isn't fully guaranteed. " | ||
"Please visit <SOME_URL> 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": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds the Note: the detection attribute is needed when doing e.g. import torchvision.models as M
M.detection # <- directly accessing the attribute but in a lot of patterns this gets bypassed, typically when doing from torchvision.models.detection import ssd or even just import torchvision.models.detection |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we mark the entire |
||
warnings.warn( | ||
"The torchvision.models.detection module is still in Beta stage, which means " | ||
"that backward compatibility isn't fully guaranteed. " | ||
"Please visit <SOME_URL> to learn more about what we are planning to change in future versions. " | ||
"To silence this warning, please call torchvision.models.enable_beta_detection." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes here are irrelevant - this is specific to pass our tests