设置加载数据集时的transform
参数如下即可:
from torchvision import datasets, transforms
transform = transforms.Compose(
[
transforms.Grayscale(num_output_channels=1),
transforms.ToTensor()
]
)
data = datasets.CIFAR10(root=".", download=True,transform=transform)