How to Read a JPEG or PNG Image in PyTorch
In this article, we are going to discuss how to Read a JPEG or PNG Image using PyTorch in Python.
In PyTorch, the image_read() method is used to read an image as input and return a tensor of size [C, H, W], where C represents a number of channels and H, W represents height and width respectively. The below syntax is used to read a JPEG or PNG image in PyTorch.
- p: This is image path with image name.
Return: This method return a tensor of size [C, H, W].
The below image is used for demonstration:
The following program is to understand how to read jpg images.
The following program is to understand how to read png images.