0
0
PyTorchml~10 mins

Why custom data pipelines handle real data in PyTorch - Test Your Understanding

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

Complete the code to import the PyTorch data loader module.

PyTorch
from torch.utils.data import [1]
Drag options to blanks, or click blank then click option'
ADataLoader
BDataset
CTensor
Dnn
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Dataset instead of DataLoader
Importing nn which is for neural networks
2fill in blank
medium

Complete the code to define a custom dataset class inheriting from PyTorch's Dataset.

PyTorch
class CustomDataset([1]):
    def __init__(self, data):
        self.data = data
    def __len__(self):
        return len(self.data)
    def __getitem__(self, idx):
        return self.data[idx]
Drag options to blanks, or click blank then click option'
ADataLoader
BTensor
CDataset
DModule
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from DataLoader instead of Dataset
Using Module which is for models
3fill in blank
hard

Fix the error in the data loading loop to get batches from the data loader.

PyTorch
for [1] in data_loader:
    inputs, labels = batch
    print(inputs.shape, labels.shape)
Drag options to blanks, or click blank then click option'
Abatch
Bdata
Cinputs
Dlabels
Attempts:
3 left
💡 Hint
Common Mistakes
Using inputs or labels as loop variable
Using data which is not defined here
4fill in blank
hard

Fill both blanks to create a data loader with batch size 32 and shuffling enabled.

PyTorch
data_loader = DataLoader(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
Using batch size 64 when 32 is asked
Setting shuffle to False which disables random order
5fill in blank
hard

Fill all three blanks to transform raw data into tensors and normalize it in the custom dataset.

PyTorch
import torch
from torchvision import transforms

class CustomDataset(Dataset):
    def __init__(self, data):
        self.transform = transforms.Compose([
            transforms.ToTensor(),
            transforms.Normalize(mean=[1], std=[2])
        ])
        self.data = data
    def __getitem__(self, idx):
        sample = self.data[idx]
        sample = self.transform(sample)
        return sample
    def __len__(self):
        return len(self.data)
Drag options to blanks, or click blank then click option'
A[0.5, 0.5, 0.5]
B[0.229, 0.224, 0.225]
C[0.485, 0.456, 0.406]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping mean and std values
Using incorrect normalization values