Shortcuts

RandomHorizontalFlip

class torchvision.transforms.RandomHorizontalFlip(p=0.5)[source]

Horizontally flip the given image randomly with a given probability. If the image is torch Tensor, it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions

Parameters:

p (float) – probability of the image being flipped. Default value is 0.5

Examples using RandomHorizontalFlip:

Getting started with transforms v2

Getting started with transforms v2

Illustration of transforms

Illustration of transforms

Transforms v2: End-to-end object detection/segmentation example

Transforms v2: End-to-end object detection/segmentation example

How to use CutMix and MixUp

How to use CutMix and MixUp

How to write your own v2 transforms

How to write your own v2 transforms

How to write your own TVTensor class

How to write your own TVTensor class

Torchscript support

Torchscript support
forward(img)[source]
Parameters:

img (PIL Image or Tensor) – Image to be flipped.

Returns:

Randomly flipped image.

Return type:

PIL Image or Tensor

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources