0
0
PyTorchml~10 mins

Custom detection dataset 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 PyTorch Dataset class.

PyTorch
from torch.utils.data import [1]
Drag options to blanks, or click blank then click option'
ADataLoader
BTensor
CDataset
DModule
Attempts:
3 left
💡 Hint
Common Mistakes
Importing DataLoader instead of Dataset
Importing Tensor or Module which are unrelated here
2fill in blank
medium

Complete the code to initialize the dataset with image paths and annotations.

PyTorch
class CustomDataset(Dataset):
    def __init__(self, [1], annotations):
        self.images = images
        self.annotations = annotations
Drag options to blanks, or click blank then click option'
Adata
Bself
Clabels
Dimages
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'self' as a parameter name
Using 'labels' or 'data' which are not the parameter names here
3fill in blank
hard

Fix the error in the __len__ method to return dataset size.

PyTorch
def __len__(self):
    return [1](self.images)
Drag options to blanks, or click blank then click option'
Alen
Bsize
Ccount
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using count() which is not a built-in function for lists
Using size() or length() which are not valid Python functions
4fill in blank
hard

Fill both blanks to load an image and its annotation in __getitem__.

PyTorch
def __getitem__(self, idx):
    image = Image.open(self.images[[1]])
    annotation = self.annotations[[2]]
    return image, annotation
Drag options to blanks, or click blank then click option'
Aidx
B0
C1
Dself
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 instead of idx, which always returns the first or second item
Using 'self' which is invalid as an index
5fill in blank
hard

Fill all three blanks to apply a transform to the image if provided.

PyTorch
def __getitem__(self, idx):
    image = Image.open(self.images[idx])
    annotation = self.annotations[idx]
    if [1] is not None:
        image = [2](image)
    return [3], annotation
Drag options to blanks, or click blank then click option'
Aself.transform
Btransform
Cimage
Dself
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'transform' without self, which is undefined
Returning the original image variable name incorrectly