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

[BETA] Horizontally flip the input with a given probability.


The RandomHorizontalFlip transform is in Beta stage, and while we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue:, and you can also check out to learn more about the APIs that we suspect might involve future changes.

If the input is a torch.Tensor or a Datapoint (e.g. Image, Video, BoundingBox 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.


p (float, optional) – probability of the input being flipped. Default value is 0.5

Examples using RandomHorizontalFlip:

Transforms v2: End-to-end object detection example

Transforms v2: End-to-end object detection example


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources