read_image¶
- torchvision.io.read_image(path: str, mode: ImageReadMode = ImageReadMode.UNCHANGED, apply_exif_orientation: bool = False) Tensor [source]¶
Reads a JPEG, PNG or GIF image into a 3 dimensional RGB or grayscale Tensor.
The values of the output tensor are in uint8 in [0, 255] for most cases. If the image is a 16-bit png, then the output tensor is uint16 in [0, 65535] (supported from torchvision
0.21
. Since uint16 support is limited in pytorch, we recommend callingtorchvision.transforms.v2.functional.to_dtype()
withscale=True
after this function to convert the decoded image into a uint8 or float tensor.- Parameters:
path (str or
pathlib.Path
) – path of the JPEG, PNG or GIF image.mode (ImageReadMode) – the read mode used for optionally converting the image. Default:
ImageReadMode.UNCHANGED
. SeeImageReadMode
class for more information on various available modes. Ignored for GIFs.apply_exif_orientation (bool) – apply EXIF orientation transformation to the output tensor. Ignored for GIFs. Default: False.
- Returns:
output (Tensor[image_channels, image_height, image_width])
Examples using
read_image
:Getting started with transforms v2
Getting started with transforms v2Repurposing masks into bounding boxes
Repurposing masks into bounding boxesTorchscript supportVisualization utilities