0
0
PyTorchml~10 mins

Built-in datasets (torchvision.datasets) in PyTorch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the CIFAR10 dataset from torchvision.datasets.

PyTorch
from torchvision.datasets import [1]
Drag options to blanks, or click blank then click option'
AFashionMNIST
BMNIST
CCIFAR10
DImageNet
Attempts:
3 left
💡 Hint
Common Mistakes
Importing MNIST instead of CIFAR10
Using ImageNet which is not in torchvision.datasets by default
Confusing FashionMNIST with CIFAR10
2fill in blank
medium

Complete the code to download the CIFAR10 training dataset with transforms.

PyTorch
train_dataset = CIFAR10(root='./data', train=[1], download=True, transform=None)
Drag options to blanks, or click blank then click option'
ATrue
BFalse
C'train'
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting train to False loads the test set
Using string 'train' instead of boolean True
Passing 1 instead of True
3fill in blank
hard

Fix the error in the code to apply a ToTensor transform to the CIFAR10 dataset.

PyTorch
from torchvision.transforms import [1]
train_dataset = CIFAR10(root='./data', train=True, download=True, transform=ToTensor())
Drag options to blanks, or click blank then click option'
ACompose
BNormalize
CResize
DToTensor
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Compose instead of ToTensor
Using Normalize without ToTensor first
Trying to resize images instead of converting to tensor
4fill in blank
hard

Fill both blanks to create a DataLoader for the training dataset with batch size 32 and shuffling enabled.

PyTorch
from torch.utils.data import DataLoader
train_loader = DataLoader(train_dataset, batch_size=[1], shuffle=[2])
Drag options to blanks, or click blank then click option'
A32
BTrue
CFalse
D64
Attempts:
3 left
💡 Hint
Common Mistakes
Setting shuffle to False which disables random order
Using batch size 64 which is valid but not the intended answer
Confusing batch_size and shuffle parameters
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps class indices to class names from CIFAR10.

PyTorch
class_to_name = [1]: [2] for [3] in range(len(train_dataset.classes))}
Drag options to blanks, or click blank then click option'
Ai
Btrain_dataset.classes[i]
Didx
Attempts:
3 left
💡 Hint
Common Mistakes
Using idx instead of i inconsistently
Swapping keys and values
Using range without len()