Found 135 Articles for PyTorch

How to adjust the hue of an image in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 07:43:56

1K+ Views

The hue of an image refers to the three primary colors (red, blue, and yellow) and the three secondary colors (orange, green, and violet). To adjust the hue of an image, we apply adjust_hue(). It's one of the functional transforms provided by the torchvision.transforms module.adjust_hue() transformation accepts both PIL and tensor images. A tensor image is a PyTorch tensor with shape [C, H, W], where C is the number of channels, H is the image height and W is the image width. This transform also accepts a batch of tensor images.The image hue is adjusted by converting the image to ... Read More

How to compute the Cosine Similarity between two tensors in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 07:40:25

12K+ Views

To compute the cosine similarity between two tensors, we use the CosineSimilarity() function provided by the torch.nn module. It returns the cosine similarity value computed along dim.dim is an optional parameter to this function along which cosine similarity is computed.For 1D tensors, we can compute the cosine similarity along dim=0 only.For 2D tensors, we can compute cosine similarity along dim=0 or 1.The size of both tensors must be the same to compute the cosine similarity. Both tensors must be real-valued. Cosine similarity is often used to measure document similarity in text analysis.Syntaxtorch.nn.CosineSimilarity(dim=1)The default dim is set to 1. But if ... Read More

Python – PyTorch clamp() method

Shahid Akhtar Khan
Updated on 20-Jan-2022 07:37:13

5K+ Views

torch.clamp() is used to clamp all the elements in an input into the range [min, max]. It takes three parameters: the input tensor, min, and max values. The values less than the min are replaced by the min and the values greater than the max are replaced by the max.If min is not given, then there is no lower bound. If max is not given, then there is no upper bound. Suppose we set min=−0.5 and max=0.4, then the values less than −0.5 are replaced by −0.5 and values greater than 0.4 are replaced by 0.4. The values between these ... Read More

Python PyTorch – How to create an Identity Matrix?

Shahid Akhtar Khan
Updated on 20-Jan-2022 07:27:06

2K+ Views

Identity matrix, also known as Unit matrix, is a "n ☓ n" square matrix with 1's on the main diagonal and 0's elsewhere. It is the multiplicative identity of square matrices. because any square matrix multipliedUnit matrix is also called the identity matrix. Unit matrix is used as the multiplicative identity of square matrices in the matrices concept. When any square matrix is multiplied by the identity matrix, then the result doesn't change. In linear algebra, the unit matrix of size n is the n ☓ n square matrix with ones on the main diagonal and zeros elsewhere.To create an ... Read More

How to measure the mean absolute error (MAE) in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 07:22:48

4K+ Views

Mean absolute error is computed as the mean of the sum of absolute differences between the input and target (predicted and actual) values. To compute the mean absolute error in PyTorch, we apply the L1Loss() function provided by the torch.nn module. It creates a criterion that measures the mean absolute error.Both the actual and predicted values are torch tensors having the same number of elements. Both the tensors may have any number of dimensions. This function returns a tensor of a scalar value. It is a type of loss function provided by the torch.nn module. The loss functions are used ... Read More

Python – PyTorch ceil() and floor() methods

Shahid Akhtar Khan
Updated on 20-Jan-2022 07:18:48

690 Views

A ceiling value of a number is the smallest integer greater than or equal to the number. To find the ceiling of the elements of a torch tensor, we use the torch.ceil() function. This function takes a torch tensor as input parameter and returns a torch tensor with the ceil values of each element of the input tensor. This function supports only real-valued inputs. It supports torch tensors of any dimension.A floor value of a number is the largest integer less than or equal to the number. To find the floor of the elements of a torch tensor, we use ... Read More

How to adjust the contrast of an image in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 07:13:54

1K+ Views

The contrast of an image refers to the amount of color differentiation that exists between the various features of an image. To adjust the contrast of an image, we apply adjust_contrast(). It's one of the functional transforms provided by the torchvision.transforms module. This module contains many important functional transformations that can be used to perform different types manipulations on the image data.adjust_contrast() transformation accepts both PIL and tensor images. A tensor image is a PyTorch tensor with shape [C, H, W], where C is the number of channels, H is the image height, and W is the image width. This ... Read More

How to adjust the brightness of an image in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 07:10:09

1K+ Views

The brightness of an image is a measure of its intensity after the image has been captured. To adjust the brightness of an image, we apply adjust_brightness(). It's one of the functional transforms provided by the torchvision.transforms module. This module contains many important functional transformations that can be used to manipulate the image data.adjust_brightness() transformation accepts both PIL and tensor images. A tensor image is a PyTorch tensor with shape [C, H, W], where C is number of channels, H is image height, and W is image width. This transform also accepts a batch of tensor images. A batch of ... Read More

How to shuffle columns or rows of matrix in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 07:06:23

1K+ Views

A matrix in PyTorch is a 2-dimension tensor having elements of the same dtype. We can shuffle a row by another row and a column by another column. To shuffle rows or columns, we can use simple slicing and indexing as we do in Numpy.If we want to shuffle rows, then we do slicing in the row indices.To shuffle columns, we do slicing in the column indices.For example, if we want to shuffle the 1st and 2nd rows of a 3☓3 matrix, then we just shuffle the index of these rows and make a slicing to find the shuffled matrix.Let's ... Read More

How to make a grid of images in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 07:02:58

4K+ Views

The torchvision.utils package provides us with the make_grid() function to create a grid of images. The images should be torch tensors. It accepts 4D mini-batch Tensor of shape (B ☓ C ☓ H ☓ W) or a list of tensor images, all of the same size.Here, B is batch size, C is the number of channels in the image, H and W are the height and width.H ☓ W of all images should be the same.The output of this function is a torch tensor containing a grid of images. We can specify the number of images in a row using ... Read More

Previous 1 ... 4 5 6 7 8 ... 14 Next
Advertisements