Programming Articles - Page 822 of 3363

Python – PyTorch ceil() and floor() methods

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

1K+ 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

2K+ 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

2K+ 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

How to compute the area of a set of bounding boxes in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 06:57:25

1K+ Views

The torchvision.io package provides functions to perform different IO operations. To compute the area of a bounding box or a set of bounding boxes, torchvision.io package provides the box_area() function. This function takes the bounding boxes as an input parameter and returns the area of each box.The bounding boxes should be torch Tensors of size [N, 4] where N is the number of bounding boxes for which the area to be calculated. Each bounding box is specified by the coordinate (xmin, ymin, xmax, ymax). In other words − 0 ≤ xmin < xmax, and 0 ≤ ymin < ymax. The ... Read More

How to draw bounding boxes on an image in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 06:35:33

7K+ Views

The torchvision.utils package provides the draw_bounding_boxes() function to draw bounding boxes on an image. It supports images of type torch Tensor with shape (C x H x W) where C is the number of channels, and W and H are the width and height of the image, respectively.If we read an image using Pillow or OpenCV, then we would have to first convert it to a torch tensor. We can draw one or more bounding boxes on the image. This function returns an image Tensor of dtype uint8 with bounding boxes drawn.The bounding boxes should be torch Tensors of size ... Read More

How to read a JPEG or PNG image in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 06:20:33

7K+ Views

Reading the images is a very important part in image processing or computer vision related tasks. The torchvision.io package provides functions to perform different IO operations. To read an image, torchvision.io package provides the image_read() function. This function reads JPEG and PNG images. It returns a 3D RGB or Grayscale Tensor.The three dimensions of the tensor correspond to [C, H, W]. C is the number of channels, W and H are the width and height of the image, respectively.For RGB, the number of channels is 3. So, the output of the read image is a tensor of [3, H, W]. The ... Read More

Node.js - process.disconnect() Method

Mayank Agarwal
Updated on 17-Jan-2022 13:13:53

699 Views

When a Node.js process is spawned with an IPC channel, the process.disconnect() method will close that IPC channel to the parent process, allowing the child process to exit or finish gracefully. The process will exit once there are no other connections keeping it alive.Syntaxprocess.disconnect()Example 1Create two files with the names "parent.js" and "child.js" and copy the following code snippets. After creating the file, use the command "node parent.js" to run parent.js.parent.js// process.channel Property Demo Example // Importing the child_process modules const fork = require('child_process').fork; // Attaching the child process file const child_file = 'child.js'; // Spawning/calling child ... Read More

Node.js - dnsPromises.resolve6() Method

Mayank Agarwal
Updated on 17-Jan-2022 13:06:06

134 Views

The dnsPromises.resolve6() method uses the DNS protocol to resolve the IPv6 addresses (AAAA records) for the hostname. The promise is resolved with an array of IPv6 addresses.Syntaxdns.resolve6(hostname, [options])Parametershostname – This parameter takes input for hostname to be resolved.options – It can have the following options −ttl – It defines the Time-To-Live (TTL) for each record.Example 1Create a file with the name "resolve6.js" and copy the following code snippet. After creating the file, use the command "node resolve6.js" to run this code as shown in the example below −// dns.resolve6() Demo Example // Importing the dns module const dns = ... Read More

Advertisements