0
0
Computer Visionml~10 mins

Dataset bias in vision in Computer Vision - Interactive Code Practice

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

Complete the code to load images from a folder using torchvision.

Computer Vision
from torchvision import datasets, transforms

transform = transforms.Compose([transforms.Resize((128, 128)), transforms.ToTensor()])
dataset = datasets.ImageFolder(root='data/train', transform=[1])
Drag options to blanks, or click blank then click option'
Atransform
Btransforms
Cdatasets
DImageFolder
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the module name 'transforms' instead of the transform pipeline.
Passing the dataset class 'datasets' instead of the transform.
Passing the class 'ImageFolder' instead of the transform.
2fill in blank
medium

Complete the code to split the dataset into training and validation sets.

Computer Vision
from torch.utils.data import random_split

train_size = int(0.8 * len(dataset))
val_size = len(dataset) - train_size
train_dataset, val_dataset = random_split(dataset, [[1], val_size])
Drag options to blanks, or click blank then click option'
Aval_size
Btrain_size
Clen(dataset)
D0.8
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping train_size and val_size in the split sizes.
Using the dataset length directly instead of the split sizes.
3fill in blank
hard

Fix the error in the code that creates a DataLoader for the validation set.

Computer Vision
from torch.utils.data import DataLoader

val_loader = DataLoader(val_dataset, batch_size=32, shuffle=[1])
Drag options to blanks, or click blank then click option'
ATrue
BNone
CFalse
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting shuffle to True for validation data.
Passing None or 0 which are invalid for shuffle parameter.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters images with labels less than 5 and maps them to their file paths.

Computer Vision
filtered_images = {img_path: label for img_path, label in dataset.imgs if label [1] 5 and img_path.endswith([2])}
Drag options to blanks, or click blank then click option'
A<
B>
C'.jpg'
D'.png'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for label filtering.
Using '.png' when images are '.jpg'.
5fill in blank
hard

Fill all three blanks to define a function that checks if a dataset is biased by comparing class counts and returns True if any class count is less than 10.

Computer Vision
def is_biased(dataset):
    counts = {}
    for _, label in dataset:
        counts[label] = counts.get([1], 0) + 1
    return any(count < [2] for count in counts.values()) or len(counts) < [3]
Drag options to blanks, or click blank then click option'
Alabel
B10
C5
Dlen(dataset)
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong key in counts.get().
Using wrong threshold values for counts or class number.