Shahid Akhtar Khan has Published 120 Answers

How to upsample a given multi-channel temporal, spatial or volumetric data in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 20-Jan-2022 08:28:44

A temporal data can be represented as a 1D tensor, and spatial data as 2D tensor while a volumetric data can be represented as a 3D tensor. The Upsample class provided by torch.nn module supports these types of data to be upsampled. But these data must be in the form ... Read More

How to adjust saturation of an image in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 20-Jan-2022 08:25:31

The saturation of an image refers to the intensity of a color. The higher the saturation of a color, the more vivid it is. The lower the saturation of a color, the closer it is to gray.To adjust the saturation of an image, we apply adjust_saturation(). It's one of the ... Read More

How to apply linear transformation to the input data in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 20-Jan-2022 08:21:13

We can apply a linear transformation to the input data using the torch.nn.Linear() module. It supports input data of type TensorFloat32. This is applied as a layer in the deep neural networks to perform linear transformation. The linear transform used −y = x * W ^ T + bHere x ... Read More

How to flatten an input tensor by reshaping it in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 20-Jan-2022 08:08:43

A tensor can be flattened into a one-dimensional tensor by reshaping it using the method torch.flatten(). This method supports both real and complex-valued input tensors. It takes a torch tensor as its input and returns a torch tensor flattened into one dimension.It takes two optional parameters, start_dim and end_dim. If ... Read More

How to compute the cross entropy loss between input and target tensors in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 20-Jan-2022 07:57:35

To compute the cross entropy loss between the input and target (predicted and actual) values, we apply the function CrossEntropyLoss(). It is accessed from the torch.nn module. It creates a criterion that measures the cross entropy loss. It is a type of loss function provided by the torch.nn module.The loss ... Read More

How to measure the mean squared error(squared L2 norm) in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 20-Jan-2022 07:53:40

Mean squared error is computed as the mean of the squared differences between the input and target (predicted and actual) values. To compute the mean squared error in PyTorch, we apply the MSELoss() function provided by the torch.nn module. It creates a criterion that measures the mean squared error. It ... Read More

How to compute pairwise distance between two vectors in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 20-Jan-2022 07:46:51

A vector in PyTorch is a 1D tensor. To compute pairwise distance between two vectors, we can use the PairwiseDistance() function. It uses p-norm to compute the pairwise distance. PairwiseDistance is basically a class provided by the torch.nn module.The size of both the vectors must be same.Pairwise distance can be computed ... Read More

How to adjust the hue of an image in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 20-Jan-2022 07:43:56

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 ... Read More

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

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 20-Jan-2022 07:40:25

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 ... Read More

Python – PyTorch clamp() method

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 20-Jan-2022 07:37:13

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 ... Read More

Advertisements