Shortcuts

RandomHorizontalFlip

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

Horizontally flip the input with a given probability.

If the input is a torch.Tensor or a TVTensor (e.g. Image, Video, BoundingBoxes etc.) it can have arbitrary number of leading batch dimensions. For example, the image can have [..., C, H, W] shape. A bounding box can have [..., 4] shape.

Parameters:

p (float, optional) – probability of the input 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
transform(inpt: Any, params: Dict[str, Any]) Any[source]

Method to override for custom transforms.

See How to write your own v2 transforms

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