pytorch 读取图片并转化成4为tensor

image_name="D:/PythonIDLE/car.png"

# loader使用torchvision中自带的transforms函数

loader = torchvision.transforms.Compose([

torchvision.transforms.ToTensor()])

# 输入图片地址

# 返回tensor变量

def image_loader(image_name):

image = Image.open(image_name).convert('RGB')

image = loader(image).unsqueeze(0)

return image.to(torch.float)

im1=image_loader(image_name)

你可能感兴趣的:(pytorch 读取图片并转化成4为tensor)