0
0
PyTorchml~10 mins

Image dataset from folders 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 image dataset loader.

PyTorch
from torchvision.datasets import [1]
Drag options to blanks, or click blank then click option'
AImageFolder
BDataLoader
Ctransforms
Ddatasets
Attempts:
3 left
💡 Hint
Common Mistakes
Using DataLoader instead of ImageFolder for loading images.
Importing transforms instead of ImageFolder.
2fill in blank
medium

Complete the code to create an ImageFolder dataset from the 'data/train' folder.

PyTorch
dataset = ImageFolder(root='[1]')
Drag options to blanks, or click blank then click option'
Atrain_data
Bdata/test
Cdata/train
Dimages/train
Attempts:
3 left
💡 Hint
Common Mistakes
Using the test folder path instead of train.
Using a wrong folder name.
3fill in blank
hard

Fix the error in the code to apply transforms to the ImageFolder dataset.

PyTorch
from torchvision import transforms

transform = transforms.Compose([transforms.Resize(256), transforms.CenterCrop(224), transforms.ToTensor()])
dataset = ImageFolder(root='data/train', [1]=transform)
Drag options to blanks, or click blank then click option'
Atransformer
Btransforms
Ctransformations
Dtransform
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'transforms' instead of 'transform' as parameter name.
Using 'transformations' or 'transformer' which are invalid.
4fill in blank
hard

Fill both blanks to create a DataLoader for the dataset with batch size 32 and shuffling enabled.

PyTorch
from torch.utils.data import [1]
dataloader = [2](dataset, batch_size=32, shuffle=True)
Drag options to blanks, or click blank then click option'
ADataLoader
BDataset
Cdataloader
DLoader
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Dataset instead of DataLoader.
Using lowercase 'dataloader' which is not a class name.
5fill in blank
hard

Fill all three blanks to print the class names from the ImageFolder dataset.

PyTorch
class_names = dataset.[1]
for i, class_name in enumerate(class_names):
    print(f"Class [2]: [3]")
Drag options to blanks, or click blank then click option'
Aclasses
Bi
Cclass_name
Dlabels
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'labels' instead of 'classes' attribute.
Printing wrong variables inside the loop.