Commit e15e81f1 authored by Stefan Otte's avatar Stefan Otte Committed by Francisco Massa
Browse files

Improve docs of functional transforms (#602)

Give a short example of how to build a transform pipeline for a
segmentation task.
parent f91a1823
...@@ -3,7 +3,11 @@ torchvision.transforms ...@@ -3,7 +3,11 @@ torchvision.transforms
.. currentmodule:: torchvision.transforms .. currentmodule:: torchvision.transforms
Transforms are common image transforms. They can be chained together using :class:`Compose` Transforms are common image transformations. They can be chained together using :class:`Compose`.
Additionally, there is the :mod:`torchvision.transforms.functional` module.
Functional transforms give fine-grained control over the transformations.
This is useful if you have to build a more complex transformation pipeline
(e.g. in the case of segmentation tasks).
.. autoclass:: Compose .. autoclass:: Compose
...@@ -78,5 +82,24 @@ Generic Transforms ...@@ -78,5 +82,24 @@ Generic Transforms
Functional Transforms Functional Transforms
--------------------- ---------------------
Functional transforms give you fine-grained control of the transformation pipeline.
As opposed to the transformations above, functional transforms don't contain a random number
generator for their parameters.
That means you have to specify/generate all parameters, but you can reuse the functional transform.
For example, you can apply a functional transform to multiple images like this:
.. code:: python
import torchvision.transforms.functional as TF
import random
def my_segmentation_transforms(image, segmentation):
if random.random() > 5:
angle = random.randint(-30, 30)
image = TF.rotate(image, angle)
segmentation = TF.rotate(segmentation, angle)
# more transforms ...
return image, segmentation
.. automodule:: torchvision.transforms.functional .. automodule:: torchvision.transforms.functional
:members: :members:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment