RandomVerticalFlip() Method in Python PyTorch Last Updated : 03 Jun, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we are going to discuss RandomVerticalFlip() Method in PyTorch using Python. RandomVerticalFlip() Method RandomVerticalFlip() method of torchvision.transforms module is used to vertically flip the image at a random angle with a given probability. This accepts a PIL image and a tensor image as an input. The tensor image is a PyTorch tensor with [C, H, W] shape, where C represents the number of channels and H, W represents the height and width respectively. This method returns a randomly flipped image. Syntax: torchvision.transforms.RandomVerticalFlip(p) Parameter: p: p is the probability of the image being flipped.img: input image. Returns: This method returns a randomly flipped image. This method returns vertically flipped image if P=1, returns original image if P=0 and if p in between the range of 0 to 1 then P is the probability to return the vertically flipped image. The below image is used for demonstration: Example 1: The following program is to understand the RandomVerticalFlip() Method when the probability is 1. Python3 # import required libraries import torch import torchvision.transforms as T from PIL import Image # read input image from computer img = Image.open('a.png') # define a transform transform = T.RandomVerticalFlip(p=1) # apply above defined transform to # input image img = transform(img) # display result img.show() Output: Example 2: The following program is to understand the RandomVerticalFlip() Method when the probability is in the range of 0 to 1. Python3 # import required libraries import torch import torchvision.transforms as T from PIL import Image # read input image from computer img = Image.open('a.png') # define a transform transform = T.RandomVerticalFlip(p=0.5) # apply above defined transform to # input image img = transform(img) # display result img.show() Output: Comment More infoAdvertise with us Next Article Python PyTorch â RandomHorizontalFlip() Function M mukulsomukesh Follow Improve Article Tags : Python Python-PyTorch Practice Tags : python Similar Reads RandomResizedCrop() Method in Python PyTorch In this article, we are going to discuss RandomResizedCrop() method in Pytorch using Python. RandomResizedCrop() method RandomResizedCrop() method of torchvision.transforms module is used to crop a random area of the image and resized this image to the given size. This method accepts both PIL Image 2 min read Python PyTorch â RandomHorizontalFlip() Function In this article, we will discuss the RandomHorizontalFlip() Method in PyTorch Python. RandomHorizontalFlip() method RandomHorizontalFlip() method of torchvision.transforms module is used to horizontally flip the given image at a random angle with a given probability. This method accepts a PIL and te 2 min read Python - Pytorch randn() method PyTorch torch.randn() returns a tensor defined by the variable argument size (sequence of integers defining the shape of the output tensor), containing random numbers from standard normal distribution. Syntax: torch.randn(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad= 3 min read Python - PyTorch trunc() method PyTorch torch.trunc() method returns a new tensor with the truncated integer values of the elements of input/ after removing the decimal portion of the number. Syntax: torch.trunc(input, out=None) Arguments input: This is input tensor. out: The output tensor. Return: It returns a Tensor. Let's see t 1 min read random.triangular() method in Python triangular() is an inbuilt method of the random module. It is used to return a random floating point number within a range with a bias towards one extreme. Syntax : random.triangular(low, high, mode) Parameters : low : the lower limit of the random number high : the upper limit of the random number 2 min read Python - PyTorch add() method PyTorch torch.add() method adds a constant value to each element of the input tensor and returns a new modified tensor. Syntax: torch.add(inp, c, out=None) Arguments inp: This is input tensor. c: The value that is to be added to every element of tensor. out: This is optional parameter and it is the 1 min read Like