torchvision is a PyTorch companion library for loading image datasets and converting image objects into tensors. It provides a convenient MNIST loader for quick computer-vision experiments. section 3.1.1
A typical MNIST workflow uses torchvision to:
- Download and select the predefined training or testing split. section 3.1.1
- Apply transforms.ToTensor() so PIL images become tensors with values from 0.0 to 1.0. section 3.1.1
- Expose grayscale MNIST examples with shape (1, 28, 28): one channel, 28-pixel width, and 28-pixel height. section 3.1.1
Load MNIST as tensors
Use torchvision.datasets.MNIST("./data", train=True, download=True, transform=transforms.ToTensor()) for training data, and change train to False for testing data.
