Shahid Akhtar Khan has Published 120 Answers

How to draw binary random numbers (0 or 1) from a Bernoulli distribution in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 27-Jan-2022 06:27:18

To draw binary random numbers (0 or 1) from a Bernoulli distribution, we apply the torch.bernoulli() method. The input to this method is a torch tensor containing the probabilities of drawing 1. These probabilities are used to draw binary random numbers (0 or 1).As the input tensor contains the probabilities, ... Read More

torch.normal() Method in Python PyTorch

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 27-Jan-2022 06:10:04

To create a tensor of random numbers drawn from separate normal distributions whose mean and std are given, we apply the torch.normal() method. This method takes two input parameters − mean and std.mean is a tensor with the mean of each output element’s normal distribution, andstd is a tensor with ... Read More

torch.polar() Method in Python PyTorch

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 27-Jan-2022 06:03:29

With given absolute values and angles, we can construct a complex number in PyTorch using torch.polar() method. The absolute value and angles must be float or double. Both the absolute value and the angle must be of the same type.If abs is a float, then angle must also be float.If ... Read More

How to compute the Hessian of a given scalar function in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 27-Jan-2022 05:55:46

The hessian() function computes the Hessian of a given function. The hessian() function can be accessed from the torch.autograd.functional module. The function whose Hessian is being computed takes a tensor as the input and returns a tuple of tensors or a tensor. The hessian() function returns a tensor with the ... Read More

How to compute the Jacobian of a given function in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 27-Jan-2022 05:46:57

The jacobian() function computes the Jacobian of a given function. The jacobian() function can be accessed from the torch.autograd.functional module. The function whose Jacobian is being computed takes a tensor as the input and returns a tuple of tensors or a tensor. The jacobian() function returns a tensor with Jacobian ... Read More

How to adjust the sharpness of an image in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 25-Jan-2022 08:58:11

To adjust the sharpness of an image, we apply adjust_sharpness(). It's one of the functional transforms provided by the torchvision.transforms module. adjust_sharpness() 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, ... Read More

How to construct a complex tensor with the given real and imaginary parts in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 25-Jan-2022 08:51:23

With given real and imaginary parts, we can construct a complex number in PyTorch using torch.complex() method. The real and imaginary parts must be float or double. Both the real and imaginary parts must be of the same type. If the real part is float, then the imaginary must also ... Read More

How to define a simple Convolutional Neural Network in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 25-Jan-2022 08:45:27

To define a simple convolutional neural network (CNN), we could use the following steps −StepsFirst we import the important libraries and packages. We try to implement a simple CNN in PyTorch. In all the following examples, the required Python library is torch. Make sure you have already installed it.import torch ... Read More

How to define a simple artificial neural network in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 25-Jan-2022 08:39:11

To define a simple artificial neural network (ANN), we could use the following steps −StepsFirst we import the important libraries and packages. We try to implement a simple ANN in PyTorch. In all the following examples, the required Python library is torch. Make sure you have already installed it.import torch ... Read More

How to load a Computer Vision dataset in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 25-Jan-2022 08:33:23

There are many datasets available in Pytorch related to computer vision tasks. The torch.utils.data.Dataset provides different types of datasets. The torchvision.datasets is a subclass of torch.utils.data.Dataset and has many datasets related to images and videos. PyTorch also provides us a torch.utils.data.DataLoader which is used to load multiple samples from a ... Read More

Advertisements