Skip to content

Commit 58f834a

Browse files
authored
Bunch of doc edits (pytorch#7906)
1 parent ce441f6 commit 58f834a

File tree

5 files changed

+52
-20
lines changed

5 files changed

+52
-20
lines changed

docs/source/transforms.rst

+28-17
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,33 @@ tasks (image classification, detection, segmentation, video classification).
3333
from torchvision import tv_tensors
3434
3535
img = torch.randint(0, 256, size=(3, H, W), dtype=torch.uint8)
36-
bboxes = torch.randint(0, H // 2, size=(3, 4))
37-
bboxes[:, 2:] += bboxes[:, :2]
38-
bboxes = tv_tensors.BoundingBoxes(bboxes, format="XYXY", canvas_size=(H, W))
36+
boxes = torch.randint(0, H // 2, size=(3, 4))
37+
boxes[:, 2:] += boxes[:, :2]
38+
boxes = tv_tensors.BoundingBoxes(boxes, format="XYXY", canvas_size=(H, W))
3939
4040
# The same transforms can be used!
41-
img, bboxes = transforms(img, bboxes)
41+
img, boxes = transforms(img, boxes)
4242
# And you can pass arbitrary input structures
43-
output_dict = transforms({"image": img, "bboxes": bboxes})
43+
output_dict = transforms({"image": img, "boxes": boxes})
4444
4545
Transforms are typically passed as the ``transform`` or ``transforms`` argument
4646
to the :ref:`Datasets <datasets>`.
4747

48-
.. TODO: Reader guide, i.e. what to read depending on what you're looking for
49-
.. TODO: add link to getting started guide here.
48+
Start here
49+
----------
50+
51+
Whether you're new to Torchvision transforms, or you're already experienced with
52+
them, we encourage you to start with
53+
:ref:`sphx_glr_auto_examples_transforms_plot_transforms_getting_started.py` in
54+
order to learn more about what can be done with the new v2 transforms.
55+
56+
Then, browse the sections in below this page for general information and
57+
performance tips. The available transforms and functionals are listed in the
58+
:ref:`API reference <v2_api_ref>`.
59+
60+
More information and tutorials can also be found in our :ref:`example gallery
61+
<gallery>`, e.g. :ref:`sphx_glr_auto_examples_transforms_plot_transforms_e2e.py`
62+
or :ref:`sphx_glr_auto_examples_transforms_plot_custom_transforms.py`.
5063

5164
.. _conventions:
5265

@@ -98,25 +111,21 @@ advantages compared to the v1 ones (in ``torchvision.transforms``):
98111

99112
- They can transform images **but also** bounding boxes, masks, or videos. This
100113
provides support for tasks beyond image classification: detection, segmentation,
101-
video classification, etc.
114+
video classification, etc. See
115+
:ref:`sphx_glr_auto_examples_transforms_plot_transforms_getting_started.py`
116+
and :ref:`sphx_glr_auto_examples_transforms_plot_transforms_e2e.py`.
102117
- They support more transforms like :class:`~torchvision.transforms.v2.CutMix`
103-
and :class:`~torchvision.transforms.v2.MixUp`.
118+
and :class:`~torchvision.transforms.v2.MixUp`. See
119+
:ref:`sphx_glr_auto_examples_transforms_plot_cutmix_mixup.py`.
104120
- They're :ref:`faster <transforms_perf>`.
105121
- They support arbitrary input structures (dicts, lists, tuples, etc.).
106122
- Future improvements and features will be added to the v2 transforms only.
107123

108-
.. TODO: Add link to e2e example for first bullet point.
109-
110124
These transforms are **fully backward compatible** with the v1 ones, so if
111125
you're already using tranforms from ``torchvision.transforms``, all you need to
112126
do to is to update the import to ``torchvision.transforms.v2``. In terms of
113127
output, there might be negligible differences due to implementation differences.
114128

115-
To learn more about the v2 transforms, check out
116-
:ref:`sphx_glr_auto_examples_transforms_plot_transforms_getting_started.py`.
117-
118-
.. TODO: make sure link is still good!!
119-
120129
.. note::
121130

122131
The v2 transforms are still BETA, but at this point we do not expect
@@ -184,7 +193,7 @@ This is very much like the :mod:`torch.nn` package which defines both classes
184193
and functional equivalents in :mod:`torch.nn.functional`.
185194

186195
The functionals support PIL images, pure tensors, or :ref:`TVTensors
187-
<tv_tensors>`, e.g. both ``resize(image_tensor)`` and ``resize(bboxes)`` are
196+
<tv_tensors>`, e.g. both ``resize(image_tensor)`` and ``resize(boxes)`` are
188197
valid.
189198

190199
.. note::
@@ -248,6 +257,8 @@ be derived from ``torch.nn.Module``.
248257

249258
See also: :ref:`sphx_glr_auto_examples_others_plot_scripted_tensor_transforms.py`.
250259

260+
.. _v2_api_ref:
261+
251262
V2 API reference - Recommended
252263
------------------------------
253264

docs/source/tv_tensors.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ TVTensors
77

88
TVTensors are :class:`torch.Tensor` subclasses which the v2 :ref:`transforms
99
<transforms>` use under the hood to dispatch their inputs to the appropriate
10-
lower-level kernels. Most users do not need to manipulate TVTensors directly and
11-
can simply rely on dataset wrapping - see e.g.
12-
:ref:`sphx_glr_auto_examples_transforms_plot_transforms_e2e.py`.
10+
lower-level kernels. Most users do not need to manipulate TVTensors directly.
11+
12+
Refer to
13+
:ref:`sphx_glr_auto_examples_transforms_plot_transforms_getting_started.py` for
14+
an introduction to TVTensors, or
15+
:ref:`sphx_glr_auto_examples_transforms_plot_tv_tensors.py` for more advanced
16+
info.
1317

1418
.. autosummary::
1519
:toctree: generated/

gallery/README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
.. _gallery:
2+
13
Examples and tutorials
24
======================

gallery/transforms/plot_transforms_e2e.py

+13
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,16 @@
166166
print(f"{[type(target) for target in targets] = }")
167167
for name, loss_val in loss_dict.items():
168168
print(f"{name:<20}{loss_val:.3f}")
169+
170+
# %%
171+
# Training References
172+
# -------------------
173+
#
174+
# From there, you can check out the `torchvision references
175+
# <https://github.com/pytorch/vision/tree/main/references>`_ where you'll find
176+
# the actual training scripts we use to train our models.
177+
#
178+
# **Disclaimer** The code in our references is more complex than what you'll
179+
# need for your own use-cases: this is because we're supporting different
180+
# backends (PIL, tensors, TVTensors) and different transforms namespaces (v1 and
181+
# v2). So don't be afraid to simplify and only keep what you need.

gallery/transforms/plot_transforms_getting_started.py

+2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@
217217
# can still be transformed by some transforms like
218218
# :class:`~torchvision.transforms.v2.SanitizeBoundingBoxes`!).
219219
#
220+
# .. _transforms_datasets_intercompatibility:
221+
#
220222
# Transforms and Datasets intercompatibility
221223
# ------------------------------------------
222224
#

0 commit comments

Comments
 (0)