@@ -4,15 +4,34 @@ torchvision.transforms
4
4
.. currentmodule :: torchvision.transforms
5
5
6
6
Transforms are common image transformations. They can be chained together using :class: `Compose `.
7
- Additionally, there is the :mod: `torchvision.transforms.functional ` module.
8
- Functional transforms give fine-grained control over the transformations.
7
+ Most transform classes have a function equivalent: :ref: `functional
8
+ transforms <functional_transforms>` give fine-grained control over the
9
+ transformations.
9
10
This is useful if you have to build a more complex transformation pipeline
10
11
(e.g. in the case of segmentation tasks).
11
12
12
- All transformations accept PIL Image, Tensor Image or batch of Tensor Images as input. Tensor Image is a tensor with
13
- ``(C, H, W) `` shape, where ``C `` is a number of channels, ``H `` and ``W `` are image height and width. Batch of
14
- Tensor Images is a tensor of ``(B, C, H, W) `` shape, where ``B `` is a number of images in the batch. Deterministic or
15
- random transformations applied on the batch of Tensor Images identically transform all the images of the batch.
13
+ Most transformations accept both `PIL <https://pillow.readthedocs.io >`_
14
+ images and tensor images, although some transformations are :ref: `PIL-only
15
+ <transforms_pil_only>` and some are :ref: `tensor-only
16
+ <transforms_tensor_only>`. The :ref: `conversion_transforms ` may be used to
17
+ convert to and from PIL images.
18
+
19
+ The transformations that accept tensor images also accept batches of tensor
20
+ images. A Tensor Image is a tensor with ``(C, H, W) `` shape, where ``C `` is a
21
+ number of channels, ``H `` and ``W `` are image height and width. A batch of
22
+ Tensor Images is a tensor of ``(B, C, H, W) `` shape, where ``B `` is a number
23
+ of images in the batch.
24
+
25
+ The expected range of the values of a tensor image is implicitely defined by
26
+ the tensor dtype. Tensor images with a float dtype are expected to have
27
+ values in ``[0, 1) ``. Tensor images with an integer dtype are expected to
28
+ have values in ``[0, MAX_DTYPE] `` where ``MAX_DTYPE `` is the largest value
29
+ that can be represented in that dtype.
30
+
31
+ Randomized transformations will apply the same transformation to all the
32
+ images of a given batch, but they will produce different transformations
33
+ across calls. For reproducible transformations across calls, you may use
34
+ :ref: `functional transforms <functional_transforms >`.
16
35
17
36
.. warning ::
18
37
@@ -117,13 +136,16 @@ Transforms on PIL Image and torch.\*Tensor
117
136
.. autoclass :: GaussianBlur
118
137
:members:
119
138
139
+ .. _transforms_pil_only :
140
+
120
141
Transforms on PIL Image only
121
142
----------------------------
122
143
123
144
.. autoclass :: RandomChoice
124
145
125
146
.. autoclass :: RandomOrder
126
147
148
+ .. _transforms_tensor_only :
127
149
128
150
Transforms on torch.\* Tensor only
129
151
---------------------------------
@@ -139,6 +161,7 @@ Transforms on torch.\*Tensor only
139
161
140
162
.. autoclass :: ConvertImageDtype
141
163
164
+ .. _conversion_transforms :
142
165
143
166
Conversion Transforms
144
167
---------------------
@@ -173,13 +196,16 @@ The new transform can be used standalone or mixed-and-matched with existing tran
173
196
:members:
174
197
175
198
199
+ .. _functional_transforms :
200
+
176
201
Functional Transforms
177
202
---------------------
178
203
179
204
Functional transforms give you fine-grained control of the transformation pipeline.
180
205
As opposed to the transformations above, functional transforms don't contain a random number
181
206
generator for their parameters.
182
- That means you have to specify/generate all parameters, but you can reuse the functional transform.
207
+ That means you have to specify/generate all parameters, but the functional transform will give you
208
+ reproducible results across calls.
183
209
184
210
Example:
185
211
you can apply a functional transform with the same parameters to multiple images like this:
0 commit comments