pytorch读取单通道图片

data_transform = transforms.Compose([
    transforms.Resize(32),
    transforms.CenterCrop(28),
    transforms.Grayscale(num_output_channels=1),
    transforms.ToTensor()
])
# 读入图片
train_dataset = datasets.ImageFolder(root='./single_channel/',
                                     transform=data_transform,
                                     )

这段代码的关键在于,要把transforms.ToTensor()给放在transforms.Grayscale(num_output_channels=1)框架的下面,也就是说,在进行图片操作的时候,先剪裁–>读入通道–>张量化

你可能感兴趣的:(python)