0
0
Computer Visionml~20 mins

Data loading with torchvision in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Torchvision DataLoader Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
Atorch.Size([32, 32, 3, 8])
Btorch.Size([3, 8, 32, 32])
Ctorch.Size([8, 32, 32, 3])
Dtorch.Size([8, 3, 32, 32])
Attempts:
2 left
💡 Hint
Remember batch size is the first dimension in the batch tensor.
🧠 Conceptual
intermediate
1:30remaining
Purpose of torchvision transforms
What is the main purpose of using transforms in torchvision datasets?
ATo increase the dataset size by duplicating images
BTo convert images to tensors and apply preprocessing like normalization
CTo load images faster from disk
DTo change the file format of images on disk
Attempts:
2 left
💡 Hint
Think about what happens before feeding images to a model.
Hyperparameter
advanced
1:30remaining
Effect of shuffle=True in DataLoader
What effect does setting shuffle=True have when creating a DataLoader?
ARandomizes the order of data samples at each epoch
BLoads data samples in sorted order by label
CDuplicates data samples to increase dataset size
DLoads only a subset of the dataset
Attempts:
2 left
💡 Hint
Think about how shuffling affects training data order.
🔧 Debug
advanced
2: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))
ATypeError because Normalize expects a tensor but receives a PIL image
BRuntimeError because batch size is too small
CValueError because mean and std lengths do not match channels
DNo error, code runs successfully
Attempts:
2 left
💡 Hint
Normalize requires tensor input, check transform order.
Model Choice
expert
2: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?
Abatch_size=1, shuffle=False, num_workers=0
Bbatch_size=16, shuffle=True, num_workers=0
Cbatch_size=64, shuffle=True, num_workers=4
Dbatch_size=128, shuffle=False, num_workers=0
Attempts:
2 left
💡 Hint
Consider batch size, shuffling, and parallel data loading.