文章目录
- 1. 说明
- 2. 代码测试
- 3. 结果
1. 说明
将JPEG或PNG图像读入三维RGB张量。可选地将图像转换为所需的格式。输出张量的值是uint8,在0到255之间
torchvision.io.read_image(path: str, mode: torchvision.io.image.ImageReadMode = <ImageReadMode.UNCHANGED: 0>)
- path : 获取图片地址
- ImageReadMode: 读取模式
- Return
output (Tensor[image_channels, image_height, image_width])
2. 代码测试
# -*- coding: utf-8 -*-
# @Project: zc
# @Author: zc
# @File name: os_test
# @Create time: 2022/1/4 8:38import os
import torchvisionpath = os.path.join(os.getcwd(), 'img', 'banana.jpg')
print(path)
img = torchvision.io.read_image(path)
print(img.shape)
3. 结果
D:\zc\img\banana.jpg
torch.Size([3, 256, 256])