Skip to content

Latest commit

 

History

History
49 lines (26 loc) · 1.86 KB

File metadata and controls

49 lines (26 loc) · 1.86 KB

EXERCISES

Exercise 2: Implementing a Custom Dataset Class for Fashion MNIST

In this exercise, we are going to train the multilayer perceptron from Unit 4.3 on a new dataset, Fashion MNIST, based on the PyTorch Dataset concepts introduced in Unit 4.4.

Fashion MNIST is a dataset with a same number of images and image dimension as MNIST. However, instead of handwritten digits, it contains low-resolution images of fashion objects.

Since the image format of MNIST and Fashion MNIST is identical, we can use the multilayer perceptron code from Unit 4.3 without any modification. The only adjustments we have to make is replacing the MNIST dataset code with a custom Dataset class for Fashion MNIST.

To get started, download the GitHub folder https://github.com/zalandoresearch/fashion-mnist and place the data subfolder next to the notebook. Then, implement the custom Dataset class and train the multilayer perceptron. You should get at least >85% training accuracy.

Hint: You may use the following Dataset code as a starter and fill out the missing blanks:

class MyDataset(Dataset):
    def __init__(self, ..., transform=None):

        self.transform = transform
        # ...

    def __getitem__(self, index):
        # ...
        img = torch.tensor(img).to(torch.float32)
        img = img/255.
        # ...

        if self.transform is not None:
            img = self.transform(img)

        # ...

    def __len__(self):
        return self.labels.shape[0]

You can use th notebook in this folder as a template: Unit 4 exercise 2

PS: If you get stuck, please don't hesitate to reach out for help via the forum!