Skip to content

Commit 048d974

Browse files
committed
Split transforms.rst
1 parent 14e6927 commit 048d974

File tree

3 files changed

+53
-49
lines changed

3 files changed

+53
-49
lines changed

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ architectures, and common image transformations for computer vision.
1313
models
1414
ops
1515
transforms
16+
transforms_functional
1617
utils
1718

1819
.. automodule:: torchvision

docs/source/transforms.rst

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -304,52 +304,3 @@ Generic Transforms
304304

305305
.. autoclass:: Lambda
306306

307-
308-
Functional Transforms
309-
---------------------
310-
311-
Functional transforms give you fine-grained control of the transformation pipeline.
312-
As opposed to the transformations above, functional transforms don't contain a random number
313-
generator for their parameters.
314-
That means you have to specify/generate all parameters, but you can reuse the functional transform.
315-
316-
Example:
317-
you can apply a functional transform with the same parameters to multiple images like this:
318-
319-
.. code:: python
320-
321-
import torchvision.transforms.functional as TF
322-
import random
323-
324-
def my_segmentation_transforms(image, segmentation):
325-
if random.random() > 0.5:
326-
angle = random.randint(-30, 30)
327-
image = TF.rotate(image, angle)
328-
segmentation = TF.rotate(segmentation, angle)
329-
# more transforms ...
330-
return image, segmentation
331-
332-
333-
Example:
334-
you can use a functional transform to build transform classes with custom behavior:
335-
336-
.. code:: python
337-
338-
import torchvision.transforms.functional as TF
339-
import random
340-
341-
class MyRotationTransform:
342-
"""Rotate by one of the given angles."""
343-
344-
def __init__(self, angles):
345-
self.angles = angles
346-
347-
def __call__(self, x):
348-
angle = random.choice(self.angles)
349-
return TF.rotate(x, angle)
350-
351-
rotation_transform = MyRotationTransform(angles=[-30, -15, 0, 15, 30])
352-
353-
354-
.. automodule:: torchvision.transforms.functional
355-
:members:
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
torchvision.transforms.functional
2+
=================================
3+
4+
Functional transforms give you fine-grained control of the transformation
5+
pipeline.
6+
As opposed to the stateful transformations from :mod:`torchvision.transforms`
7+
functional transforms don't contain any state or random number generator for
8+
their parameters.
9+
That means that you have to specify/generate all parameters,
10+
but you can reuse a functional transform.
11+
12+
Example:
13+
you can apply a functional transform with the same parameters to multiple
14+
images like this:
15+
16+
.. code:: python
17+
18+
import torchvision.transforms.functional as TF
19+
import random
20+
21+
def my_segmentation_transforms(image, segmentation):
22+
if random.random() > 0.5:
23+
angle = random.randint(-30, 30)
24+
image = TF.rotate(image, angle)
25+
segmentation = TF.rotate(segmentation, angle)
26+
# more transforms ...
27+
return image, segmentation
28+
29+
30+
Example:
31+
you can use a functional transform to build transform classes with custom behavior:
32+
33+
.. code:: python
34+
35+
import torchvision.transforms.functional as TF
36+
import random
37+
38+
class MyRotationTransform:
39+
"""Rotate by one of the given angles."""
40+
41+
def __init__(self, angles):
42+
self.angles = angles
43+
44+
def __call__(self, x):
45+
angle = random.choice(self.angles)
46+
return TF.rotate(x, angle)
47+
48+
rotation_transform = MyRotationTransform(angles=[-30, -15, 0, 15, 30])
49+
50+
51+
.. automodule:: torchvision.transforms.functional
52+
:members:

0 commit comments

Comments
 (0)