Found 135 Articles for PyTorch

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

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

936 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

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

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

PyTorch – torch.linalg.cond()

Shahid Akhtar Khan
Updated on 07-Jan-2022 06:30:16

177 Views

To compute the condition number of a matrix with respect to a matrix norm, we could apply torch.linalg.cond() method. It returns a new tensor with computed condition number. It accepts a matrix, a batch of matrices and also batches of matrices. A matrix is a 2D torch Tensor. It supports input of float, double, cfloat, and cdouble data typesSyntaxtorch.linalg.cond(M, p=None)ParametersM – A matrix or batch of matrices.p – A type of matrix norm to be used in computation of condition number. Default matrix norm is 2-norm.It returns a real-valued tensor of condition number.StepsWe could use the following steps to compute the ... Read More

PyTorch – How to compute the pseudoinverse of a matrix?

Shahid Akhtar Khan
Updated on 07-Jan-2022 06:26:38

461 Views

To compute the pseudoinverse of a square matrix, we could apply torch.linalg.pinv() method. It returns a new tensor with pseudoinverse of the given matrix. It accepts a matrix, a batch of matrices and also batches of matrices. A matrix is a 2D torch Tensor. It supports input of float, double, cfloat, and cdouble data types.Syntaxtorch.linalg.pinv(M)Where M is a matrix or batches of matrices.StepsWe could use the following steps to compute the pseudoinverse of a matrix −Import the required library. In all the following examples, the required Python library is torch. Make sure you have already installed it.import torchDefine a matrix. ... Read More

PyTorch – How to compute the inverse of a square matrix?

Shahid Akhtar Khan
Updated on 07-Jan-2022 06:21:14

779 Views

To compute the inverse of a square matrix, we could apply torch.linalg.inv() method. It returns a new tensor with inverse of the given matrix. It accepts a square matrix, a batch of square matrices, and also batches of square matrices.A matrix is a 2D torch Tensor. It supports input of float, double, cfloat, and cdouble data types. The inverse matrix exists if and only if the square matrix is invertible.Syntaxtorch.linalg.inv(M)Where M is a square matrix or a batch of square matrices. It returns the inverse matrix.StepsWe could use the following steps to compute the inverse of a square matrix −Import ... Read More

PyTorch – torch.linalg.solve() Method

Shahid Akhtar Khan
Updated on 07-Jan-2022 06:15:03

595 Views

To solve a square system of linear equations with unique solution, we could apply the torch.linalg.solve() method. This method takes two parameters −first, the coefficient matrix A, andsecond, the right-hand tensor b.Where A is a square matrix and b is a vector. The solution is unique if A invertible. We can solve a number of systems of linear equations. In this case, A is a batch of square matrices and b is a batch of vectors.Syntaxtorch.linalg.solve(A, b)ParametersA – Square matrix or batch of square matrices. It is the coefficient matrix of system of linear equations.b – Vector or a batch ... Read More

PyTorch – How to compute QR decomposition of a matrix?

Shahid Akhtar Khan
Updated on 07-Jan-2022 06:10:48

258 Views

torch.linalg.qr() computes the QR decomposition of a matrix or a batch of matrices. It accepts matrix and batch of matrices of float, double, cfloat and cdouble data types.It returns a named tuple (Q, R). Q is orthogonal when the matrix is real valued and unitary when matrix is complex valued. And R is an upper triangular matrix.Syntax(Q, R) = torch.linalg.qr(mat, mode='reduced')ParametersMat – Square matrix or a batch of square matrices.mode – It decides mode of QR decomposition. It is set to one of three modes, 'reduced', 'complete', and 'r'. Default is set to 'reduced'. It's an optional parameter.StepsImport the required library. In ... Read More

PyTorch – How to compute the eigenvalues and eigenvectors of a square matrix?

Shahid Akhtar Khan
Updated on 07-Jan-2022 06:08:11

1K+ Views

torch.linalg.eig() computes the Eigen value decomposition of a square matrix or a batch of square matrices. It accepts matrix and batch of matrices of float, double, cfloat and cdouble data types. It returns a named tuple (eigenvalues, eigenvectors). The eigenvalues and eigenvectors are always complex valued. The eigenvectors are given by columns of eigenvectors.Syntax(eigenvalues, eigenvectors) = torch.linalg.eig(A)Where A is a square matrix or a batch of square matrices. It returns a named tuple (eigenvalues, eigenvectors).StepsImport the required library. In all the following examples, the required Python library is torch. Make sure you have already installed it.import torchCreate a square matrix ... Read More

PyTorch – How to compute the norm of a vector or matrix?

Shahid Akhtar Khan
Updated on 07-Jan-2022 06:16:07

928 Views

To compute the norm of a vector or a matrix, we could apply torch.linalg.norm() method. It returns a new tensor with computed norm. It accepts a vector, matrix, a batch of matrices and also batches of matrices.A vector is a 1D torch Tensor where a matrix is a 2D torch Tensor. It supports input of float, double, cfloat, and cdouble data types. We can compute the norm of the matrix or batch/es of matrices along the different dimensions. For example, we could compute the norm of a matrix along dimension 0 or along dimension1.Syntaxtorch.linalg.norm(A)A is a vector, matrix or batch/s ... Read More

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