transforms.rst 18.1 KB
Newer Older
1
2
.. _transforms:

3
4
Transforming and augmenting images
==================================
Sasank Chilamkurthy's avatar
Sasank Chilamkurthy committed
5
6
7

.. currentmodule:: torchvision.transforms

Nicolas Hug's avatar
Nicolas Hug committed
8
9
10
11
Torchvision supports common computer vision transformations in the
``torchvision.transforms`` and ``torchvision.transforms.v2`` modules. Transforms
can be used to transform or augment data for training or inference of different
tasks (image classification, detection, segmentation, video classification).
12

Nicolas Hug's avatar
Nicolas Hug committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.. code:: python

    # Image Classification
    import torch
    from torchvision.transforms import v2

    H, W = 32, 32
    img = torch.randint(0, 256, size=(3, H, W), dtype=torch.uint8)

    transforms = v2.Compose([
        v2.RandomResizedCrop(size=(224, 224), antialias=True),
        v2.RandomHorizontalFlip(p=0.5),
        v2.ToDtype(torch.float32, scale=True),
        v2.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
    ])
    img = transforms(img)

.. code:: python

    # Detection (re-using imports and transforms from above)
    from torchvision import datapoints

    img = torch.randint(0, 256, size=(3, H, W), dtype=torch.uint8)
    bboxes = torch.randint(0, H // 2, size=(3, 4))
    bboxes[:, 2:] += bboxes[:, :2]
    bboxes = datapoints.BoundingBoxes(bboxes, format="XYXY", canvas_size=(H, W))

    # The same transforms can be used!
    img, bboxes = transforms(img, bboxes)
    # And you can pass arbitrary input structures
    output_dict = transforms({"image": img, "bboxes": bboxes})

Transforms are typically passed as the ``transform`` or ``transforms`` argument
to the :ref:`Datasets <datasets>`.

48
.. TODO: Reader guide, i.e. what to read depending on what you're looking for
Nicolas Hug's avatar
Nicolas Hug committed
49
50
.. TODO: add link to getting started guide here.

51
52
.. _conventions:

Nicolas Hug's avatar
Nicolas Hug committed
53
54
Supported input types and conventions
-------------------------------------
Sasank Chilamkurthy's avatar
Sasank Chilamkurthy committed
55

56
Most transformations accept both `PIL <https://pillow.readthedocs.io>`_ images
57
58
and tensor inputs. Both CPU and CUDA tensors are supported.
The result of both backends (PIL or Tensors) should be very
Nicolas Hug's avatar
Nicolas Hug committed
59
60
61
62
63
64
65
66
67
68
69
close. In general, we recommend relying on the tensor backend :ref:`for
performance <transforms_perf>`.  The :ref:`conversion transforms
<conversion_transforms>` may be used to convert to and from PIL images, or for
converting dtypes and ranges.

Tensor image are expected to be of shape ``(C, H, W)``, where ``C`` is the
number of channels, and ``H`` and ``W`` refer to height and width. Most
transforms support batched tensor input. A batch of Tensor images is a tensor of
shape ``(N, C, H, W)``, where ``N`` is a number of images in the batch. The
:ref:`v2 <v1_or_v2>` transforms generally accept an arbitrary number of leading
dimensions ``(..., C, H, W)`` and can handle batched images or batched videos.
70

Nicolas Hug's avatar
Nicolas Hug committed
71
72
73
74
.. _range_and_dtype:

Dtype and expected value range
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
75

76
The expected range of the values of a tensor image is implicitly defined by
77
the tensor dtype. Tensor images with a float dtype are expected to have
Nicolas Hug's avatar
Nicolas Hug committed
78
values in ``[0, 1]``. Tensor images with an integer dtype are expected to
79
have values in ``[0, MAX_DTYPE]`` where ``MAX_DTYPE`` is the largest value
Nicolas Hug's avatar
Nicolas Hug committed
80
81
that can be represented in that dtype. Typically, images of dtype
``torch.uint8`` are expected to have values in ``[0, 255]``.
82

Nicolas Hug's avatar
Nicolas Hug committed
83
84
Use :class:`~torchvision.transforms.v2.ToDtype` to convert both the dtype and
range of the inputs.
85

Nicolas Hug's avatar
Nicolas Hug committed
86
.. _v1_or_v2:
87

Nicolas Hug's avatar
Nicolas Hug committed
88
89
V1 or V2? Which one should I use?
---------------------------------
90

Nicolas Hug's avatar
Nicolas Hug committed
91
92
93
**TL;DR** We recommending using the ``torchvision.transforms.v2`` transforms
instead of those in ``torchvision.transforms``. They're faster and they can do
more things. Just change the import and you should be good to go.
94

Nicolas Hug's avatar
Nicolas Hug committed
95
96
97
In Torchvision 0.15 (March 2023), we released a new set of transforms available
in the ``torchvision.transforms.v2`` namespace. These transforms have a lot of
advantages compared to the v1 ones (in ``torchvision.transforms``):
98

Nicolas Hug's avatar
Nicolas Hug committed
99
100
101
102
103
104
105
106
- They can transform images **but also** bounding boxes, masks, or videos. This
  provides support for tasks beyond image classification: detection, segmentation,
  video classification, etc.
- They support more transforms like :class:`~torchvision.transforms.v2.CutMix`
  and :class:`~torchvision.transforms.v2.MixUp`.
- They're :ref:`faster <transforms_perf>`.
- They support arbitrary input structures (dicts, lists, tuples, etc.).
- Future improvements and features will be added to the v2 transforms only.
107

Nicolas Hug's avatar
Nicolas Hug committed
108
109
110
111
112
113
114
115
.. TODO: Add link to e2e example for first bullet point.

These transforms are **fully backward compatible** with the v1 ones, so if
you're already using tranforms from ``torchvision.transforms``, all you need to
do to is to update the import to ``torchvision.transforms.v2``. In terms of
output, there might be negligible differences due to implementation differences.

To learn more about the v2 transforms, check out
Nicolas Hug's avatar
Nicolas Hug committed
116
:ref:`sphx_glr_auto_examples_transforms_plot_transforms_getting_started.py`.
Nicolas Hug's avatar
Nicolas Hug committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

.. TODO: make sure link is still good!!

.. note::

    The v2 transforms are still BETA, but at this point we do not expect
    disruptive changes to be made to their public APIs. We're planning to make
    them fully stable in version 0.17. Please submit any feedback you may have
    `here <https://github.com/pytorch/vision/issues/6753>`_.

.. _transforms_perf:

Performance considerations
--------------------------

We recommend the following guidelines to get the best performance out of the
transforms:

- Rely on the v2 transforms from ``torchvision.transforms.v2``
- Use tensors instead of PIL images
- Use ``torch.uint8`` dtype, especially for resizing
- Resize with bilinear or bicubic mode

This is what a typical transform pipeline could look like:

.. code:: python

    from torchvision.transforms import v2
    transforms = v2.Compose([
        v2.ToImage(),  # Convert to tensor, only needed if you had a PIL image
        v2.ToDtype(torch.uint8, scale=True),  # optional, most input are already uint8 at this point
        # ...
        v2.RandomResizedCrop(size=(224, 224), antialias=True),  # Or Resize(antialias=True)
        # ...
        v2.ToDtype(torch.float32, scale=True),  # Normalize expects float input
        v2.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
    ])

The above should give you the best performance in a typical training environment
that relies on the :class:`torch.utils.data.DataLoader` with ``num_workers >
0``.

159
Transforms tend to be sensitive to the input strides / memory format. Some
Nicolas Hug's avatar
Nicolas Hug committed
160
transforms will be faster with channels-first images while others prefer
161
162
163
164
165
channels-last. Like ``torch`` operators, most transforms will preserve the
memory format of the input, but this may not always be respected due to
implementation details. You may want to experiment a bit if you're chasing the
very best performance.  Using :func:`torch.compile` on individual transforms may
also help factoring out the memory format variable (e.g. on
Nicolas Hug's avatar
Nicolas Hug committed
166
:class:`~torchvision.transforms.v2.Normalize`). Note that we're talking about
167
**memory format**, not :ref:`tensor shape <conventions>`.
Nicolas Hug's avatar
Nicolas Hug committed
168
169
170
171
172
173
174

Note that resize transforms like :class:`~torchvision.transforms.v2.Resize`
and :class:`~torchvision.transforms.v2.RandomResizedCrop` typically prefer
channels-last input and tend **not** to benefit from :func:`torch.compile` at
this time.

.. _functional_transforms:
175

Nicolas Hug's avatar
Nicolas Hug committed
176
177
Transform classes, functionals, and kernels
-------------------------------------------
178

Nicolas Hug's avatar
Nicolas Hug committed
179
180
181
182
183
184
Transforms are available as classes like
:class:`~torchvision.transforms.v2.Resize`, but also as functionals like
:func:`~torchvision.transforms.v2.functional.resize` in the
``torchvision.transforms.v2.functional`` namespace.
This is very much like the :mod:`torch.nn` package which defines both classes
and functional equivalents in :mod:`torch.nn.functional`.
185

Nicolas Hug's avatar
Nicolas Hug committed
186
187
188
The functionals support PIL images, pure tensors, or :ref:`datapoints
<datapoints>`, e.g. both ``resize(image_tensor)`` and ``resize(bboxes)`` are
valid.
189

Nicolas Hug's avatar
Nicolas Hug committed
190
191
192
193
194
195
196
197
.. note::

    Random transforms like :class:`~torchvision.transforms.v2.RandomCrop` will
    randomly sample some parameter each time they're called. Their functional
    counterpart (:func:`~torchvision.transforms.v2.functional.crop`) does not do
    any kind of random sampling and thus have a slighlty different
    parametrization. The ``get_params()`` class method of the transforms class
    can be used to perform parameter sampling when using the functional APIs.
198
199


Nicolas Hug's avatar
Nicolas Hug committed
200
201
202
203
204
205
206
207
208
209
The ``torchvision.transforms.v2.functional`` namespace also contains what we
call the "kernels". These are the low-level functions that implement the
core functionalities for specific types, e.g. ``resize_bounding_boxes`` or
```resized_crop_mask``. They are public, although not documented. Check the
`code
<https://github.com/pytorch/vision/blob/main/torchvision/transforms/v2/functional/__init__.py>`_
to see which ones are available (note that those starting with a leading
underscore are **not** public!). Kernels are only really useful if you want
:ref:`torchscript support <transforms_torchscript>` for types like bounding
boxes or masks.
210

Nicolas Hug's avatar
Nicolas Hug committed
211
.. _transforms_torchscript:
212

Nicolas Hug's avatar
Nicolas Hug committed
213
214
Torchscript support
-------------------
215

Nicolas Hug's avatar
Nicolas Hug committed
216
Most transform classes and functionals support torchscript. For composing
Nicolas Hug's avatar
Nicolas Hug committed
217
218
transforms, use :class:`torch.nn.Sequential` instead of
:class:`~torchvision.transforms.v2.Compose`:
219
220
221
222

.. code:: python

    transforms = torch.nn.Sequential(
Nicolas Hug's avatar
Nicolas Hug committed
223
224
        CenterCrop(10),
        Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
225
226
227
    )
    scripted_transforms = torch.jit.script(transforms)

Nicolas Hug's avatar
Nicolas Hug committed
228
229
230
231
232
233
234
235
.. warning::

    v2 transforms support torchscript, but if you call ``torch.jit.script()`` on
    a v2 **class** transform, you'll actually end up with its (scripted) v1
    equivalent.  This may lead to slightly different results between the
    scripted and eager executions due to implementation differences between v1
    and v2.

Nicolas Hug's avatar
Nicolas Hug committed
236
    If you really need torchscript support for the v2 transforms, we recommend
Nicolas Hug's avatar
Nicolas Hug committed
237
238
239
240
241
242
243
244
    scripting the **functionals** from the
    ``torchvision.transforms.v2.functional`` namespace to avoid surprises.


Also note that the functionals only support torchscript for pure tensors, which
are always treated as images. If you need torchscript support for other types
like bounding boxes or masks, you can rely on the :ref:`low-level kernels
<functional_transforms>`.
245

Nicolas Hug's avatar
Nicolas Hug committed
246
247
248
249
For any custom transformations to be used with ``torch.jit.script``, they should
be derived from ``torch.nn.Module``.

See also: :ref:`sphx_glr_auto_examples_others_plot_scripted_tensor_transforms.py`.
250

Nicolas Hug's avatar
Nicolas Hug committed
251
252
V2 API reference - Recommended
------------------------------
253

254
Geometry
Nicolas Hug's avatar
Nicolas Hug committed
255
256
257
258
^^^^^^^^

Resizing
""""""""
259

260
261
262
263
.. autosummary::
    :toctree: generated/
    :template: class.rst

264
    v2.Resize
265
266
267
    v2.ScaleJitter
    v2.RandomShortestSize
    v2.RandomResize
Nicolas Hug's avatar
Nicolas Hug committed
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

Functionals

.. autosummary::
    :toctree: generated/
    :template: function.rst

    v2.functional.resize

Cropping
""""""""

.. autosummary::
    :toctree: generated/
    :template: class.rst

284
285
    v2.RandomCrop
    v2.RandomResizedCrop
286
    v2.RandomIoUCrop
287
288
289
    v2.CenterCrop
    v2.FiveCrop
    v2.TenCrop
Nicolas Hug's avatar
Nicolas Hug committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311

Functionals

.. autosummary::
    :toctree: generated/
    :template: function.rst

    v2.functional.crop
    v2.functional.resized_crop
    v2.functional.ten_crop
    v2.functional.center_crop
    v2.functional.five_crop

Others
""""""

.. autosummary::
    :toctree: generated/
    :template: class.rst

    v2.RandomHorizontalFlip
    v2.RandomVerticalFlip
312
    v2.Pad
313
314
    v2.RandomZoomOut
    v2.RandomRotation
315
316
    v2.RandomAffine
    v2.RandomPerspective
317
    v2.ElasticTransform
318

Nicolas Hug's avatar
Nicolas Hug committed
319
320
321
322
323
324
325
326
327
328
329
330
331
Functionals

.. autosummary::
    :toctree: generated/
    :template: function.rst

    v2.functional.horizontal_flip
    v2.functional.vertical_flip
    v2.functional.pad
    v2.functional.rotate
    v2.functional.affine
    v2.functional.perspective
    v2.functional.elastic
332

333
Color
Nicolas Hug's avatar
Nicolas Hug committed
334
^^^^^
Sasank Chilamkurthy's avatar
Sasank Chilamkurthy committed
335

336
337
338
339
.. autosummary::
    :toctree: generated/
    :template: class.rst

340
    v2.ColorJitter
341
    v2.RandomChannelPermutation
342
    v2.RandomPhotometricDistort
343
344
345
346
347
348
349
350
351
    v2.Grayscale
    v2.RandomGrayscale
    v2.GaussianBlur
    v2.RandomInvert
    v2.RandomPosterize
    v2.RandomSolarize
    v2.RandomAdjustSharpness
    v2.RandomAutocontrast
    v2.RandomEqualize
352

Nicolas Hug's avatar
Nicolas Hug committed
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
Functionals

.. autosummary::
    :toctree: generated/
    :template: function.rst

    v2.functional.permute_channels
    v2.functional.rgb_to_grayscale
    v2.functional.to_grayscale
    v2.functional.gaussian_blur
    v2.functional.invert
    v2.functional.posterize
    v2.functional.solarize
    v2.functional.adjust_sharpness
    v2.functional.autocontrast
    v2.functional.adjust_contrast
    v2.functional.equalize
    v2.functional.adjust_brightness
    v2.functional.adjust_saturation
    v2.functional.adjust_hue
    v2.functional.adjust_gamma


376
Composition
Nicolas Hug's avatar
Nicolas Hug committed
377
^^^^^^^^^^^
Sasank Chilamkurthy's avatar
Sasank Chilamkurthy committed
378

379
380
381
.. autosummary::
    :toctree: generated/
    :template: class.rst
vfdev's avatar
vfdev committed
382

383
384
385
386
    v2.Compose
    v2.RandomApply
    v2.RandomChoice
    v2.RandomOrder
vfdev's avatar
vfdev committed
387

388
Miscellaneous
Nicolas Hug's avatar
Nicolas Hug committed
389
^^^^^^^^^^^^^
vfdev's avatar
vfdev committed
390

391
392
393
.. autosummary::
    :toctree: generated/
    :template: class.rst
Sasank Chilamkurthy's avatar
Sasank Chilamkurthy committed
394

395
396
397
398
    v2.LinearTransformation
    v2.Normalize
    v2.RandomErasing
    v2.Lambda
399
400
    v2.SanitizeBoundingBoxes
    v2.ClampBoundingBoxes
401
    v2.UniformTemporalSubsample
vfdev's avatar
vfdev committed
402

Nicolas Hug's avatar
Nicolas Hug committed
403
404
405
406
407
408
409
410
411
412
413
Functionals

.. autosummary::
    :toctree: generated/
    :template: function.rst

    v2.functional.normalize
    v2.functional.erase
    v2.functional.clamp_bounding_boxes
    v2.functional.uniform_temporal_subsample

414
.. _conversion_transforms:
415

416
Conversion
Nicolas Hug's avatar
Nicolas Hug committed
417
^^^^^^^^^^
Sasank Chilamkurthy's avatar
Sasank Chilamkurthy committed
418

Nicolas Hug's avatar
Nicolas Hug committed
419
420
421
422
.. note::
    Beware, some of these conversion transforms below will scale the values
    while performing the conversion, while some may not do any scaling. By
    scaling, we mean e.g. that a ``uint8`` -> ``float32`` would map the [0,
Nicolas Hug's avatar
Nicolas Hug committed
423
424
    255] range into [0, 1] (and vice-versa). See :ref:`range_and_dtype`.

425
426
427
.. autosummary::
    :toctree: generated/
    :template: class.rst
vfdev's avatar
vfdev committed
428

429
    v2.ToImage
Nicolas Hug's avatar
Nicolas Hug committed
430
431
432
    v2.ToPureTensor
    v2.PILToTensor
    v2.ToPILImage
Nicolas Hug's avatar
Nicolas Hug committed
433
    v2.ToDtype
vfdev's avatar
vfdev committed
434
    v2.ConvertBoundingBoxFormat
Nicolas Hug's avatar
Nicolas Hug committed
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458

functionals

.. autosummary::
    :toctree: generated/
    :template: functional.rst

    v2.functional.to_image
    v2.functional.pil_to_tensor
    v2.functional.to_pil_image
    v2.functional.to_dtype
    v2.functional.convert_bounding_box_format


Deprecated

.. autosummary::
    :toctree: generated/
    :template: class.rst

    v2.ToTensor
    v2.functional.to_tensor
    v2.ConvertImageDtype
    v2.functional.convert_image_dtype
Nicolas Hug's avatar
Nicolas Hug committed
459

460
Auto-Augmentation
Nicolas Hug's avatar
Nicolas Hug committed
461
^^^^^^^^^^^^^^^^^
462
463
464
465
466
467
468

`AutoAugment <https://arxiv.org/pdf/1805.09501.pdf>`_ is a common Data Augmentation technique that can improve the accuracy of Image Classification models.
Though the data augmentation policies are directly linked to their trained dataset, empirical studies show that
ImageNet policies provide significant improvements when applied to other datasets.
In TorchVision we implemented 3 policies learned on the following datasets: ImageNet, CIFAR10 and SVHN.
The new transform can be used standalone or mixed-and-matched with existing transforms:

469
470
471
.. autosummary::
    :toctree: generated/
    :template: class.rst
472

473
474
475
476
    v2.AutoAugment
    v2.RandAugment
    v2.TrivialAugmentWide
    v2.AugMix
477

Nicolas Hug's avatar
Nicolas Hug committed
478

479
CutMix - MixUp
Nicolas Hug's avatar
Nicolas Hug committed
480
^^^^^^^^^^^^^^
481

482
CutMix and MixUp are special transforms that
483
are meant to be used on batches rather than on individual images, because they
484
485
are combining pairs of images together. These can be used after the dataloader
(once the samples are batched), or part of a collation function. See
Nicolas Hug's avatar
Nicolas Hug committed
486
:ref:`sphx_glr_auto_examples_transforms_plot_cutmix_mixup.py` for detailed usage examples.
487
488
489
490
491

.. autosummary::
    :toctree: generated/
    :template: class.rst

Nicolas Hug's avatar
Nicolas Hug committed
492
493
    v2.CutMix
    v2.MixUp
494

Nicolas Hug's avatar
Nicolas Hug committed
495
496
Developer tools
^^^^^^^^^^^^^^^
497

Nicolas Hug's avatar
Nicolas Hug committed
498
499
500
.. autosummary::
    :toctree: generated/
    :template: function.rst
501

Nicolas Hug's avatar
Nicolas Hug committed
502
    v2.functional.register_kernel
503

504

Nicolas Hug's avatar
Nicolas Hug committed
505
506
V1 API Reference
----------------
507

Nicolas Hug's avatar
Nicolas Hug committed
508
509
Geometry
^^^^^^^^
510

Nicolas Hug's avatar
Nicolas Hug committed
511
512
513
.. autosummary::
    :toctree: generated/
    :template: class.rst
514

Nicolas Hug's avatar
Nicolas Hug committed
515
516
517
518
519
520
521
522
523
524
525
526
527
    Resize
    RandomCrop
    RandomResizedCrop
    CenterCrop
    FiveCrop
    TenCrop
    Pad
    RandomRotation
    RandomAffine
    RandomPerspective
    ElasticTransform
    RandomHorizontalFlip
    RandomVerticalFlip
528
529


Nicolas Hug's avatar
Nicolas Hug committed
530
531
Color
^^^^^
532

Nicolas Hug's avatar
Nicolas Hug committed
533
534
535
.. autosummary::
    :toctree: generated/
    :template: class.rst
536

Nicolas Hug's avatar
Nicolas Hug committed
537
538
539
540
541
542
543
544
545
546
    ColorJitter
    Grayscale
    RandomGrayscale
    GaussianBlur
    RandomInvert
    RandomPosterize
    RandomSolarize
    RandomAdjustSharpness
    RandomAutocontrast
    RandomEqualize
547

Nicolas Hug's avatar
Nicolas Hug committed
548
549
Composition
^^^^^^^^^^^
550

Nicolas Hug's avatar
Nicolas Hug committed
551
552
553
.. autosummary::
    :toctree: generated/
    :template: class.rst
554

Nicolas Hug's avatar
Nicolas Hug committed
555
556
557
558
    Compose
    RandomApply
    RandomChoice
    RandomOrder
559

Nicolas Hug's avatar
Nicolas Hug committed
560
561
Miscellaneous
^^^^^^^^^^^^^
562

Nicolas Hug's avatar
Nicolas Hug committed
563
564
565
.. autosummary::
    :toctree: generated/
    :template: class.rst
566

Nicolas Hug's avatar
Nicolas Hug committed
567
568
569
570
    LinearTransformation
    Normalize
    RandomErasing
    Lambda
571

Nicolas Hug's avatar
Nicolas Hug committed
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
Conversion
^^^^^^^^^^

.. note::
    Beware, some of these conversion transforms below will scale the values
    while performing the conversion, while some may not do any scaling. By
    scaling, we mean e.g. that a ``uint8`` -> ``float32`` would map the [0,
    255] range into [0, 1] (and vice-versa). See :ref:`range_and_dtype`.
    
.. autosummary::
    :toctree: generated/
    :template: class.rst

    ToPILImage
    ToTensor
    PILToTensor
    ConvertImageDtype

Auto-Augmentation
^^^^^^^^^^^^^^^^^

`AutoAugment <https://arxiv.org/pdf/1805.09501.pdf>`_ is a common Data Augmentation technique that can improve the accuracy of Image Classification models.
Though the data augmentation policies are directly linked to their trained dataset, empirical studies show that
ImageNet policies provide significant improvements when applied to other datasets.
In TorchVision we implemented 3 policies learned on the following datasets: ImageNet, CIFAR10 and SVHN.
The new transform can be used standalone or mixed-and-matched with existing transforms:

.. autosummary::
    :toctree: generated/
    :template: class.rst

    AutoAugmentPolicy
    AutoAugment
    RandAugment
    TrivialAugmentWide
    AugMix



Functional Transforms
^^^^^^^^^^^^^^^^^^^^^

.. currentmodule:: torchvision.transforms.functional
615

616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
.. autosummary::
    :toctree: generated/
    :template: function.rst

    adjust_brightness
    adjust_contrast
    adjust_gamma
    adjust_hue
    adjust_saturation
    adjust_sharpness
    affine
    autocontrast
    center_crop
    convert_image_dtype
    crop
    equalize
    erase
    five_crop
    gaussian_blur
635
    get_dimensions
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
    get_image_num_channels
    get_image_size
    hflip
    invert
    normalize
    pad
    perspective
    pil_to_tensor
    posterize
    resize
    resized_crop
    rgb_to_grayscale
    rotate
    solarize
    ten_crop
    to_grayscale
    to_pil_image
    to_tensor
    vflip