Skip to content

Commit 473fc34

Browse files
NicolasHugpmeiervfdev-5mpearce25
authored
[Cherry-pick] Bunch of doc and fixes cherry-picks for release/0.15 (#7334)
Co-authored-by: Philip Meier <[email protected]> Co-authored-by: vfdev <[email protected]> Co-authored-by: mpearce25 <[email protected]>
1 parent ee7fd31 commit 473fc34

34 files changed

+1947
-163
lines changed

.github/workflows/test-linux-cpu.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
fi
4040
4141
# Create Conda Env
42-
conda create -yp ci_env python="${PYTHON_VERSION}" numpy libpng jpeg scipy
42+
conda create -yp ci_env --quiet python="${PYTHON_VERSION}" numpy libpng jpeg scipy 'ffmpeg<4.3'
4343
conda activate /work/ci_env
4444
4545
# Install PyTorch, Torchvision, and testing libraries
@@ -50,8 +50,8 @@ jobs:
5050
-c nvidia "pytorch-${CHANNEL}"::pytorch[build="*${VERSION}*"] \
5151
"${CUDATOOLKIT}"
5252
python3 setup.py develop
53-
python3 -m pip install pytest pytest-mock 'av<10'
53+
python3 -m pip install --progress-bar=off pytest pytest-mock 'av<10'
5454
5555
# Run Tests
5656
python3 -m torch.utils.collect_env
57-
python3 -m pytest --junitxml=test-results/junit.xml -v --durations 20
57+
python3 -m pytest --junitxml=test-results/junit.xml --durations 20

.github/workflows/test-linux-gpu.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
fi
4444
4545
# Create Conda Env
46-
conda create -yp ci_env python="${PYTHON_VERSION}" numpy libpng jpeg scipy
46+
conda create -yp ci_env --quiet python="${PYTHON_VERSION}" numpy libpng jpeg scipy 'ffmpeg<4.3'
4747
conda activate /work/ci_env
4848
4949
# Install PyTorch, Torchvision, and testing libraries
@@ -54,8 +54,8 @@ jobs:
5454
-c nvidia "pytorch-${CHANNEL}"::pytorch[build="*${VERSION}*"] \
5555
"${CUDATOOLKIT}"
5656
python3 setup.py develop
57-
python3 -m pip install pytest pytest-mock 'av<10'
57+
python3 -m pip install --progress-bar=off pytest pytest-mock 'av<10'
5858
5959
# Run Tests
6060
python3 -m torch.utils.collect_env
61-
python3 -m pytest --junitxml=test-results/junit.xml -v --durations 20
61+
python3 -m pytest --junitxml=test-results/junit.xml --durations 20

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ sphinx-gallery>=0.11.1
55
sphinx==5.0.0
66
tabulate
77
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
8+
pycocotools

docs/source/beta_status.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@
44

55
class BetaStatus(Directive):
66
has_content = True
7+
text = "The {api_name} is in Beta stage, and backward compatibility is not guaranteed."
78

89
def run(self):
9-
api_name = " ".join(self.content)
10-
text = f"The {api_name} is in Beta stage, and backward compatibility is not guaranteed."
10+
text = self.text.format(api_name=" ".join(self.content))
1111
return [nodes.warning("", nodes.paragraph("", "", nodes.Text(text)))]
1212

1313

14+
class V2BetaStatus(BetaStatus):
15+
text = (
16+
"The {api_name} is in Beta stage, and while we do not expect major breaking changes, "
17+
"some APIs may still change according to user feedback. Please submit any feedback you may have "
18+
"in this issue: https://github.com/pytorch/vision/issues/6753, and you can also check "
19+
"out https://github.com/pytorch/vision/issues/7319 to learn "
20+
"more about the APIs that we suspect might involve future changes."
21+
)
22+
23+
1424
def setup(app):
1525
app.add_directive("betastatus", BetaStatus)
26+
app.add_directive("v2betastatus", V2BetaStatus)
1627
return {
1728
"version": "0.1",
1829
"parallel_read_safe": True,

docs/source/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

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

36+
torchvision.disable_beta_transforms_warning()
37+
import torchvision.datapoints # Don't remove, otherwise the docs for datapoints aren't linked properly
38+
3639
# -- General configuration ------------------------------------------------
3740

3841
# Required version of sphinx is set from docs/requirements.txt
@@ -60,6 +63,7 @@
6063
"gallery_dirs": "auto_examples", # path to where to save gallery generated output
6164
"backreferences_dir": "gen_modules/backreferences",
6265
"doc_module": ("torchvision",),
66+
"remove_config_comments": True,
6367
}
6468

6569
napoleon_use_ivar = True

docs/source/datapoints.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Datapoints
2+
==========
3+
4+
.. currentmodule:: torchvision.datapoints
5+
6+
Datapoints are tensor subclasses which the :mod:`~torchvision.transforms.v2` v2 transforms use under the hood to
7+
dispatch their inputs to the appropriate lower-level kernels. Most users do not
8+
need to manipulate datapoints directly and can simply rely on dataset wrapping -
9+
see e.g. :ref:`sphx_glr_auto_examples_plot_transforms_v2_e2e.py`.
10+
11+
.. autosummary::
12+
:toctree: generated/
13+
:template: class.rst
14+
15+
Image
16+
Video
17+
BoundingBoxFormat
18+
BoundingBox
19+
Mask

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ architectures, and common image transformations for computer vision.
3232
:caption: Package Reference
3333

3434
transforms
35+
datapoints
3536
models
3637
datasets
3738
utils

docs/source/transforms.rst

Lines changed: 120 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ Transforming and augmenting images
55

66
.. currentmodule:: torchvision.transforms
77

8+
9+
.. note::
10+
In 0.15, we released a new set of transforms available in the
11+
``torchvision.transforms.v2`` namespace, which add support for transforming
12+
not just images but also bounding boxes, masks, or videos. These transforms
13+
are fully backward compatible with the current ones, and you'll see them
14+
documented below with a `v2.` prefix. To get started with those new
15+
transforms, you can check out
16+
:ref:`sphx_glr_auto_examples_plot_transforms_v2_e2e.py`.
17+
Note that these transforms are still BETA, and while we don't expect major
18+
breaking changes in the future, some APIs may still change according to user
19+
feedback. Please submit any feedback you may have `here
20+
<https://github.com/pytorch/vision/issues/6753>`_, and you can also check
21+
out `this issue <https://github.com/pytorch/vision/issues/7319>`_ to learn
22+
more about the APIs that we suspect might involve future changes.
23+
824
Transforms are common image transformations available in the
925
``torchvision.transforms`` module. They can be chained together using
1026
:class:`Compose`.
@@ -14,11 +30,10 @@ transformations.
1430
This is useful if you have to build a more complex transformation pipeline
1531
(e.g. in the case of segmentation tasks).
1632

17-
Most transformations accept both `PIL <https://pillow.readthedocs.io>`_
18-
images and tensor images, although some transformations are :ref:`PIL-only
19-
<transforms_pil_only>` and some are :ref:`tensor-only
20-
<transforms_tensor_only>`. The :ref:`conversion_transforms` may be used to
21-
convert to and from PIL images.
33+
Most transformations accept both `PIL <https://pillow.readthedocs.io>`_ images
34+
and tensor images, although some transformations are PIL-only and some are
35+
tensor-only. The :ref:`conversion_transforms` may be used to convert to and from
36+
PIL images, or for converting dtypes and ranges.
2237

2338
The transformations that accept tensor images also accept batches of tensor
2439
images. A Tensor Image is a tensor with ``(C, H, W)`` shape, where ``C`` is a
@@ -70,8 +85,10 @@ The following examples illustrate the use of the available transforms:
7085
produce the same results.
7186

7287

73-
Scriptable transforms
74-
---------------------
88+
Transforms scriptability
89+
------------------------
90+
91+
.. TODO: Add note about v2 scriptability (in next PR)
7592
7693
In order to script the transformations, please use ``torch.nn.Sequential`` instead of :class:`Compose`.
7794

@@ -89,100 +106,141 @@ Make sure to use only scriptable transformations, i.e. that work with ``torch.Te
89106
For any custom transformations to be used with ``torch.jit.script``, they should be derived from ``torch.nn.Module``.
90107

91108

92-
Compositions of transforms
93-
--------------------------
109+
Geometry
110+
--------
94111

95112
.. autosummary::
96113
:toctree: generated/
97114
:template: class.rst
98115

99-
Compose
116+
Resize
117+
v2.Resize
118+
v2.ScaleJitter
119+
v2.RandomShortestSize
120+
v2.RandomResize
121+
RandomCrop
122+
v2.RandomCrop
123+
RandomResizedCrop
124+
v2.RandomResizedCrop
125+
v2.RandomIoUCrop
126+
CenterCrop
127+
v2.CenterCrop
128+
FiveCrop
129+
v2.FiveCrop
130+
TenCrop
131+
v2.TenCrop
132+
Pad
133+
v2.Pad
134+
v2.RandomZoomOut
135+
RandomRotation
136+
v2.RandomRotation
137+
RandomAffine
138+
v2.RandomAffine
139+
RandomPerspective
140+
v2.RandomPerspective
141+
ElasticTransform
142+
v2.ElasticTransform
143+
RandomHorizontalFlip
144+
v2.RandomHorizontalFlip
145+
RandomVerticalFlip
146+
v2.RandomVerticalFlip
100147

101148

102-
Transforms on PIL Image and torch.\*Tensor
103-
------------------------------------------
149+
Color
150+
-----
104151

105152
.. autosummary::
106153
:toctree: generated/
107154
:template: class.rst
108155

109-
CenterCrop
110156
ColorJitter
111-
FiveCrop
157+
v2.ColorJitter
158+
v2.RandomPhotometricDistort
112159
Grayscale
113-
Pad
114-
RandomAffine
115-
RandomApply
116-
RandomCrop
160+
v2.Grayscale
117161
RandomGrayscale
118-
RandomHorizontalFlip
119-
RandomPerspective
120-
RandomResizedCrop
121-
RandomRotation
122-
RandomVerticalFlip
123-
Resize
124-
TenCrop
162+
v2.RandomGrayscale
125163
GaussianBlur
164+
v2.GaussianBlur
126165
RandomInvert
166+
v2.RandomInvert
127167
RandomPosterize
168+
v2.RandomPosterize
128169
RandomSolarize
170+
v2.RandomSolarize
129171
RandomAdjustSharpness
172+
v2.RandomAdjustSharpness
130173
RandomAutocontrast
174+
v2.RandomAutocontrast
131175
RandomEqualize
176+
v2.RandomEqualize
132177

133-
134-
.. _transforms_pil_only:
135-
136-
Transforms on PIL Image only
137-
----------------------------
178+
Composition
179+
-----------
138180

139181
.. autosummary::
140182
:toctree: generated/
141183
:template: class.rst
142184

185+
Compose
186+
v2.Compose
187+
RandomApply
188+
v2.RandomApply
143189
RandomChoice
190+
v2.RandomChoice
144191
RandomOrder
192+
v2.RandomOrder
145193

146-
.. _transforms_tensor_only:
147-
148-
Transforms on torch.\*Tensor only
149-
---------------------------------
194+
Miscellaneous
195+
-------------
150196

151197
.. autosummary::
152198
:toctree: generated/
153199
:template: class.rst
154200

155201
LinearTransformation
202+
v2.LinearTransformation
156203
Normalize
204+
v2.Normalize
157205
RandomErasing
158-
ConvertImageDtype
206+
v2.RandomErasing
207+
Lambda
208+
v2.Lambda
209+
v2.SanitizeBoundingBox
210+
v2.ClampBoundingBox
211+
v2.UniformTemporalSubsample
159212

160213
.. _conversion_transforms:
161214

162-
Conversion Transforms
163-
---------------------
215+
Conversion
216+
----------
164217

218+
.. note::
219+
Beware, some of these conversion transforms below will scale the values
220+
while performing the conversion, while some may not do any scaling. By
221+
scaling, we mean e.g. that a ``uint8`` -> ``float32`` would map the [0,
222+
255] range into [0, 1] (and vice-versa).
223+
165224
.. autosummary::
166225
:toctree: generated/
167226
:template: class.rst
168227

169228
ToPILImage
229+
v2.ToPILImage
230+
v2.ToImagePIL
170231
ToTensor
232+
v2.ToTensor
171233
PILToTensor
234+
v2.PILToTensor
235+
v2.ToImageTensor
236+
ConvertImageDtype
237+
v2.ConvertDtype
238+
v2.ConvertImageDtype
239+
v2.ToDtype
240+
v2.ConvertBoundingBoxFormat
172241

173-
174-
Generic Transforms
175-
------------------
176-
177-
.. autosummary::
178-
:toctree: generated/
179-
:template: class.rst
180-
181-
Lambda
182-
183-
184-
Automatic Augmentation Transforms
185-
---------------------------------
242+
Auto-Augmentation
243+
-----------------
186244

187245
`AutoAugment <https://arxiv.org/pdf/1805.09501.pdf>`_ is a common Data Augmentation technique that can improve the accuracy of Image Classification models.
188246
Though the data augmentation policies are directly linked to their trained dataset, empirical studies show that
@@ -196,9 +254,13 @@ The new transform can be used standalone or mixed-and-matched with existing tran
196254

197255
AutoAugmentPolicy
198256
AutoAugment
257+
v2.AutoAugment
199258
RandAugment
259+
v2.RandAugment
200260
TrivialAugmentWide
261+
v2.TrivialAugmentWide
201262
AugMix
263+
v2.AugMix
202264

203265
.. _functional_transforms:
204266

@@ -207,6 +269,14 @@ Functional Transforms
207269

208270
.. currentmodule:: torchvision.transforms.functional
209271

272+
273+
.. note::
274+
You'll find below the documentation for the existing
275+
``torchvision.transforms.functional`` namespace. The
276+
``torchvision.transforms.v2.functional`` namespace exists as well and can be
277+
used! The same functionals are present, so you simply need to change your
278+
import to rely on the ``v2`` namespace.
279+
210280
Functional transforms give you fine-grained control of the transformation pipeline.
211281
As opposed to the transformations above, functional transforms don't contain a random number
212282
generator for their parameters.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../astronaut.jpg
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../dog2.jpg

gallery/assets/coco/instances.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"images": [{"file_name": "000000000001.jpg", "height": 512, "width": 512, "id": 1}, {"file_name": "000000000002.jpg", "height": 500, "width": 500, "id": 2}], "annotations": [{"segmentation": [[40.0, 511.0, 26.0, 487.0, 28.0, 438.0, 17.0, 397.0, 24.0, 346.0, 38.0, 306.0, 61.0, 250.0, 111.0, 206.0, 111.0, 187.0, 120.0, 183.0, 136.0, 159.0, 159.0, 150.0, 181.0, 148.0, 182.0, 132.0, 175.0, 132.0, 168.0, 120.0, 154.0, 102.0, 153.0, 62.0, 188.0, 35.0, 191.0, 29.0, 208.0, 20.0, 210.0, 22.0, 227.0, 16.0, 240.0, 16.0, 276.0, 31.0, 285.0, 39.0, 301.0, 88.0, 297.0, 108.0, 281.0, 128.0, 273.0, 138.0, 266.0, 138.0, 264.0, 153.0, 257.0, 162.0, 256.0, 174.0, 284.0, 197.0, 300.0, 221.0, 303.0, 236.0, 337.0, 258.0, 357.0, 306.0, 361.0, 351.0, 358.0, 511.0]], "iscrowd": 0, "image_id": 1, "bbox": [17.0, 16.0, 344.0, 495.0], "category_id": 1, "id": 1}, {"segmentation": [[0.0, 411.0, 43.0, 401.0, 99.0, 395.0, 105.0, 351.0, 124.0, 326.0, 181.0, 294.0, 227.0, 280.0, 245.0, 262.0, 259.0, 234.0, 262.0, 207.0, 271.0, 140.0, 283.0, 139.0, 301.0, 162.0, 309.0, 181.0, 341.0, 175.0, 362.0, 139.0, 369.0, 139.0, 377.0, 163.0, 378.0, 203.0, 381.0, 212.0, 380.0, 220.0, 382.0, 242.0, 404.0, 264.0, 392.0, 293.0, 384.0, 295.0, 385.0, 316.0, 399.0, 343.0, 391.0, 448.0, 452.0, 475.0, 457.0, 494.0, 436.0, 498.0, 402.0, 491.0, 369.0, 488.0, 366.0, 496.0, 319.0, 496.0, 302.0, 485.0, 226.0, 469.0, 128.0, 456.0, 74.0, 458.0, 29.0, 439.0, 0.0, 445.0]], "iscrowd": 0, "image_id": 2, "bbox": [0.0, 139.0, 457.0, 359.0], "category_id": 18, "id": 2}]}

0 commit comments

Comments
 (0)