"doc/git@developer.sourcefind.cn:OpenDAS/ktransformers.git" did not exist on "1b1f417267e16e6dbde39324dadcb105271a758e"
Commit e160cce3 authored by Stefan Otte's avatar Stefan Otte Committed by Francisco Massa
Browse files

More examples of functional transforms (#1402)

parent 8c3cea7f
...@@ -89,7 +89,9 @@ Functional transforms give you fine-grained control of the transformation pipeli ...@@ -89,7 +89,9 @@ Functional transforms give you fine-grained control of the transformation pipeli
As opposed to the transformations above, functional transforms don't contain a random number As opposed to the transformations above, functional transforms don't contain a random number
generator for their parameters. generator for their parameters.
That means you have to specify/generate all parameters, but you can reuse the functional transform. 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:
Example:
you can apply a functional transform with the same parameters to multiple images like this:
.. code:: python .. code:: python
...@@ -104,5 +106,27 @@ For example, you can apply a functional transform to multiple images like this: ...@@ -104,5 +106,27 @@ For example, you can apply a functional transform to multiple images like this:
# more transforms ... # more transforms ...
return image, segmentation return image, segmentation
Example:
you can use a functional transform to build transform classes with custom behavior:
.. code:: python
import torchvision.transforms.functional as TF
import random
class MyRotationTransform:
"""Rotate by one of the given angles."""
def __init__(self, angles):
self.angles = angles
def __call__(self, x):
angle = random.choice(self.angles)
return TF.rotate(x, angle)
rotation_transform = MyRotationTransform(angles=[-30, -15, 0, 15, 30])
.. 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