RandomHorizontalFlip

class paddle.vision.transforms. RandomHorizontalFlip ( prob=0.5, keys=None ) [source]

Horizontally flip the input data randomly with a given probability.

Parameters
  • prob (float, optional) – Probability of the input data being flipped. Should be in [0, 1]. Default: 0.5

  • keys (list[str]|tuple[str], optional) – Same as BaseTransform. Default: None.

Shape:
  • img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).

  • output(PIL.Image|np.ndarray|Paddle.Tensor): A horizontal flipped image.

Returns

A callable object of RandomHorizontalFlip.

Examples

>>> import paddle
>>> fake_img = paddle.to_tensor([[[0, 0, 1], [0, 0, 1], [1, 1, 1]]])
>>> print(fake_img)
Tensor(shape=[1, 3, 3], dtype=int64, place=Place(gpu:0), stop_gradient=True,
       [[[0, 0, 1],
         [0, 0, 1],
         [1, 1, 1]]])
>>> transform = paddle.vision.transforms.RandomHorizontalFlip(prob=1)
>>> result = transform(fake_img)
>>> print(result)
Tensor(shape=[1, 3, 3], dtype=int64, place=Place(gpu:0), stop_gradient=True,
       [[[1, 0, 0],
         [1, 0, 0],
         [1, 1, 1]]])