Skip to content

Commit 5c32c84

Browse files
NicolasHugfacebook-github-bot
authored andcommitted
[fbsync] Remove import-time warning for v2 namespaces (#7853)
Summary: (Note: this ignores all push blocking failures!) Reviewed By: matteobettini Differential Revision: D48900399 fbshipit-source-id: d6752725c98312a4460e5784de09b93b4523d8f8
1 parent 2399c0a commit 5c32c84

13 files changed

+5
-129
lines changed

docs/source/conf.py

-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434

3535
sys.path.append(os.path.abspath("."))
3636

37-
torchvision.disable_beta_transforms_warning()
38-
import torchvision.datapoints # Don't remove, otherwise the docs for datapoints aren't linked properly
39-
4037
# -- General configuration ------------------------------------------------
4138

4239
# Required version of sphinx is set from docs/requirements.txt

gallery/v2_transforms/plot_custom_datapoints.py

-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
# %%
1313
import torch
14-
import torchvision
15-
16-
# We are using BETA APIs, so we deactivate the associated warning, thereby acknowledging that
17-
# some APIs may slightly change in the future
18-
torchvision.disable_beta_transforms_warning()
19-
2014
from torchvision import datapoints
2115
from torchvision.transforms import v2
2216

gallery/v2_transforms/plot_custom_transforms.py

-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99

1010
# %%
1111
import torch
12-
import torchvision
13-
14-
# We are using BETA APIs, so we deactivate the associated warning, thereby acknowledging that
15-
# some APIs may slightly change in the future
16-
torchvision.disable_beta_transforms_warning()
17-
1812
from torchvision import datapoints
1913
from torchvision.transforms import v2
2014

gallery/v2_transforms/plot_cutmix_mixup.py

-6
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@
1717

1818
# %%
1919
import torch
20-
import torchvision
2120
from torchvision.datasets import FakeData
22-
23-
# We are using BETA APIs, so we deactivate the associated warning, thereby acknowledging that
24-
# some APIs may slightly change in the future
25-
torchvision.disable_beta_transforms_warning()
26-
2721
from torchvision.transforms import v2
2822

2923

gallery/v2_transforms/plot_datapoints.py

-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
import PIL.Image
2525

2626
import torch
27-
import torchvision
28-
29-
# We are using BETA APIs, so we deactivate the associated warning, thereby acknowledging that
30-
# some APIs may slightly change in the future
31-
torchvision.disable_beta_transforms_warning()
32-
3327
from torchvision import datapoints
3428
from torchvision.transforms.v2 import functional as F
3529

gallery/v2_transforms/plot_transforms_v2.py

-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import pathlib
1212

1313
import torch
14-
import torchvision
1514

1615

1716
def load_data():
@@ -42,9 +41,6 @@ def load_data():
4241
# detection or instance and semantic segmentation. Still, the interface is the same, making
4342
# :mod:`torchvision.transforms.v2` a drop-in replacement for the existing :mod:`torchvision.transforms` API, aka v1.
4443

45-
# We are using BETA APIs, so we deactivate the associated warning, thereby acknowledging that
46-
# some APIs may slightly change in the future
47-
torchvision.disable_beta_transforms_warning()
4844
import torchvision.transforms.v2 as transforms
4945

5046
transform = transforms.Compose(

gallery/v2_transforms/plot_transforms_v2_e2e.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import torch
1717
import torch.utils.data
1818

19-
import torchvision
19+
from torchvision import models, datasets
20+
import torchvision.transforms.v2 as transforms
2021

2122

2223
def show(sample):
@@ -39,19 +40,10 @@ def show(sample):
3940
fig.show()
4041

4142

42-
# We are using BETA APIs, so we deactivate the associated warning, thereby acknowledging that
43-
# some APIs may slightly change in the future
44-
torchvision.disable_beta_transforms_warning()
45-
46-
from torchvision import models, datasets
47-
import torchvision.transforms.v2 as transforms
48-
49-
5043
# %%
5144
# We start off by loading the :class:`~torchvision.datasets.CocoDetection` dataset to have a look at what it currently
5245
# returns, and we'll see how to convert it to a format that is compatible with our new transforms.
5346

54-
5547
def load_example_coco_detection_dataset(**kwargs):
5648
# This loads fake data for illustration purposes of this example. In practice, you'll have
5749
# to replace this with the proper data

test/conftest.py

-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import numpy as np
44
import pytest
55
import torch
6-
import torchvision
7-
8-
9-
torchvision.disable_beta_transforms_warning()
106

117
from common_utils import (
128
CUDA_NOT_AVAILABLE_MSG,

test/test_transforms_v2.py

+1-51
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import itertools
22
import pathlib
33
import random
4-
import textwrap
54
import warnings
65

76
import numpy as np
@@ -11,7 +10,7 @@
1110
import torch
1211
import torchvision.transforms.v2 as transforms
1312

14-
from common_utils import assert_equal, assert_run_python_script, cpu_and_cuda
13+
from common_utils import assert_equal, cpu_and_cuda
1514
from torch.utils._pytree import tree_flatten, tree_unflatten
1615
from torchvision import datapoints
1716
from torchvision.ops.boxes import box_iou
@@ -1279,55 +1278,6 @@ def test_sanitize_bounding_boxes_errors():
12791278
transforms.SanitizeBoundingBoxes()(different_sizes)
12801279

12811280

1282-
@pytest.mark.parametrize(
1283-
"import_statement",
1284-
(
1285-
"from torchvision.transforms import v2",
1286-
"import torchvision.transforms.v2",
1287-
"from torchvision.transforms.v2 import Resize",
1288-
"import torchvision.transforms.v2.functional",
1289-
"from torchvision.transforms.v2.functional import resize",
1290-
"from torchvision import datapoints",
1291-
"from torchvision.datapoints import Image",
1292-
"from torchvision.datasets import wrap_dataset_for_transforms_v2",
1293-
),
1294-
)
1295-
@pytest.mark.parametrize("call_disable_warning", (True, False))
1296-
def test_warnings_v2_namespaces(import_statement, call_disable_warning):
1297-
if call_disable_warning:
1298-
source = f"""
1299-
import warnings
1300-
import torchvision
1301-
torchvision.disable_beta_transforms_warning()
1302-
with warnings.catch_warnings():
1303-
warnings.simplefilter("error")
1304-
{import_statement}
1305-
"""
1306-
else:
1307-
source = f"""
1308-
import pytest
1309-
with pytest.warns(UserWarning, match="v2 namespaces are still Beta"):
1310-
{import_statement}
1311-
"""
1312-
assert_run_python_script(textwrap.dedent(source))
1313-
1314-
1315-
def test_no_warnings_v1_namespace():
1316-
source = """
1317-
import warnings
1318-
with warnings.catch_warnings():
1319-
warnings.simplefilter("error")
1320-
import torchvision.transforms
1321-
from torchvision import transforms
1322-
import torchvision.transforms.functional
1323-
from torchvision.transforms import Resize
1324-
from torchvision.transforms.functional import resize
1325-
from torchvision import datasets
1326-
from torchvision.datasets import ImageNet
1327-
"""
1328-
assert_run_python_script(textwrap.dedent(source))
1329-
1330-
13311281
class TestLambda:
13321282
inputs = pytest.mark.parametrize("input", [object(), torch.empty(()), np.empty(()), "string", 1, 0.0])
13331283

torchvision/__init__.py

-17
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,3 @@ def get_video_backend():
9595

9696
def _is_tracing():
9797
return torch._C._get_tracing_state()
98-
99-
100-
_WARN_ABOUT_BETA_TRANSFORMS = True
101-
_BETA_TRANSFORMS_WARNING = (
102-
"The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. "
103-
"While we do not expect major breaking changes, some APIs may still change "
104-
"according to user feedback. Please submit any feedback you may have in "
105-
"this issue: https://github.com/pytorch/vision/issues/6753, and you can also "
106-
"check out https://github.com/pytorch/vision/issues/7319 to learn more about "
107-
"the APIs that we suspect might involve future changes. "
108-
"You can silence this warning by calling torchvision.disable_beta_transforms_warning()."
109-
)
110-
111-
112-
def disable_beta_transforms_warning():
113-
global _WARN_ABOUT_BETA_TRANSFORMS
114-
_WARN_ABOUT_BETA_TRANSFORMS = False

torchvision/datapoints/__init__.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import torch
2-
from torchvision import _BETA_TRANSFORMS_WARNING, _WARN_ABOUT_BETA_TRANSFORMS
32

43
from ._bounding_box import BoundingBoxes, BoundingBoxFormat
54
from ._datapoint import Datapoint
@@ -8,11 +7,6 @@
87
from ._torch_function_helpers import set_return_type
98
from ._video import Video
109

11-
if _WARN_ABOUT_BETA_TRANSFORMS:
12-
import warnings
13-
14-
warnings.warn(_BETA_TRANSFORMS_WARNING)
15-
1610

1711
def wrap(wrappee, *, like, **kwargs):
1812
"""[BETA] Convert a :class:`torch.Tensor` (``wrappee``) into the same :class:`~torchvision.datapoints.Datapoint` subclass as ``like``.

torchvision/datasets/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,13 @@
127127
"SintelStereo",
128128
"InStereo2k",
129129
"ETH3DStereo",
130+
"wrap_dataset_for_transforms_v2",
130131
)
131132

132133

133134
# We override current module's attributes to handle the import:
134135
# from torchvision.datasets import wrap_dataset_for_transforms_v2
135-
# with beta state v2 warning from torchvision.datapoints
136-
# We also want to avoid raising the warning when importing other attributes
137-
# from torchvision.datasets
136+
# without a cyclic error.
138137
# Ref: https://peps.python.org/pep-0562/
139138
def __getattr__(name):
140139
if name in ("wrap_dataset_for_transforms_v2",):

torchvision/transforms/v2/__init__.py

-7
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,3 @@
5555
from ._type_conversion import PILToTensor, ToImage, ToPILImage, ToPureTensor
5656

5757
from ._deprecated import ToTensor # usort: skip
58-
59-
from torchvision import _BETA_TRANSFORMS_WARNING, _WARN_ABOUT_BETA_TRANSFORMS
60-
61-
if _WARN_ABOUT_BETA_TRANSFORMS:
62-
import warnings
63-
64-
warnings.warn(_BETA_TRANSFORMS_WARNING)

0 commit comments

Comments
 (0)