Complete the code to import the torchvision datasets module.
from torchvision import [1]
The datasets module in torchvision provides easy access to popular vision datasets.
Complete the code to load the MNIST training dataset with torchvision.
train_data = datasets.MNIST(root='./data', train=[1], download=True)
Setting train=True loads the training split of MNIST.
Fix the error in the code to apply a transform that converts images to tensors.
from torchvision import transforms transform = transforms.[1]() train_data = datasets.MNIST(root='./data', train=True, download=True, transform=transform)
The correct transform class is ToTensor with capital T and capital T in Tensor.
Fill both blanks to create a DataLoader for the training data with batch size 64 and shuffling enabled.
from torch.utils.data import DataLoader train_loader = DataLoader(train_data, batch_size=[1], shuffle=[2])
Batch size 64 is common for training, and shuffle=True randomizes data order each epoch.
Fill all three blanks to create a transform pipeline that resizes images to 28x28, converts to tensor, and normalizes with mean 0.5 and std 0.5.
transform = transforms.Compose([
transforms.Resize(([1], [2])),
transforms.ToTensor(),
transforms.Normalize(mean=[[3]], std=[0.5])
])Images are resized to 28x28 pixels, normalized with mean 0.5 and std 0.5 for balanced input.