@@ -3,7 +3,11 @@ torchvision.transforms
3
3
4
4
.. currentmodule :: torchvision.transforms
5
5
6
- Transforms are common image transforms. They can be chained together using :class: `Compose `
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.
9
+ This is useful if you have to build a more complex transformation pipeline
10
+ (e.g. in the case of segmentation tasks).
7
11
8
12
.. autoclass :: Compose
9
13
@@ -78,5 +82,24 @@ Generic Transforms
78
82
Functional Transforms
79
83
---------------------
80
84
85
+ Functional transforms give you fine-grained control of the transformation pipeline.
86
+ As opposed to the transformations above, functional transforms don't contain a random number
87
+ generator for their parameters.
88
+ That means you have to specify/generate all parameters, but you can reuse the functional transform.
89
+ For example, you can apply a functional transform to multiple images like this:
90
+
91
+ .. code :: python
92
+
93
+ import torchvision.transforms.functional as TF
94
+ import random
95
+
96
+ def my_segmentation_transforms (image , segmentation ):
97
+ if random.random() > 5 :
98
+ angle = random.randint(- 30 , 30 )
99
+ image = TF .rotate(image, angle)
100
+ segmentation = TF .rotate(segmentation, angle)
101
+ # more transforms ...
102
+ return image, segmentation
103
+
81
104
.. automodule :: torchvision.transforms.functional
82
105
:members:
0 commit comments