Challenge - 5 Problems
Torchvision DataLoader Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of torchvision DataLoader batch size
What is the shape of the images batch tensor returned by this DataLoader?
Computer Vision
import torchvision.transforms as transforms from torchvision.datasets import FakeData from torch.utils.data import DataLoader transform = transforms.ToTensor() dataset = FakeData(size=100, image_size=(3, 32, 32), transform=transform) dataloader = DataLoader(dataset, batch_size=8) images, labels = next(iter(dataloader)) print(images.shape)
Attempts:
2 left
💡 Hint
Remember batch size is the first dimension in the batch tensor.
✗ Incorrect
The DataLoader returns batches with shape (batch_size, channels, height, width). Here batch_size=8, channels=3, height=32, width=32.
🧠 Conceptual
intermediate1:30remaining
Purpose of torchvision transforms
What is the main purpose of using transforms in torchvision datasets?
Attempts:
2 left
💡 Hint
Think about what happens before feeding images to a model.
✗ Incorrect
Transforms convert images to tensors and apply preprocessing steps like resizing, cropping, or normalization to prepare data for training.
❓ Hyperparameter
advanced1:30remaining
Effect of shuffle=True in DataLoader
What effect does setting shuffle=True have when creating a DataLoader?
Attempts:
2 left
💡 Hint
Think about how shuffling affects training data order.
✗ Incorrect
shuffle=True randomizes the order of samples each epoch to reduce model overfitting to data order.
🔧 Debug
advanced2:00remaining
Error when using torchvision transforms
What error will this code raise and why?
import torchvision.transforms as transforms
from torchvision.datasets import FakeData
from torch.utils.data import DataLoader
transform = transforms.Normalize(mean=[0.5], std=[0.5])
dataset = FakeData(size=10, image_size=(3, 32, 32), transform=transform)
dataloader = DataLoader(dataset, batch_size=2)
batch = next(iter(dataloader))
Attempts:
2 left
💡 Hint
Normalize requires tensor input, check transform order.
✗ Incorrect
Normalize expects a tensor input but FakeData returns PIL images by default, causing a TypeError.
❓ Model Choice
expert2:30remaining
Choosing the best DataLoader setting for large image dataset
You have a large image dataset and want to train a model efficiently using torchvision DataLoader. Which setting combination is best?
Attempts:
2 left
💡 Hint
Consider batch size, shuffling, and parallel data loading.
✗ Incorrect
A larger batch size with shuffling and multiple workers speeds up training and improves generalization.