February 2018
Intermediate to advanced
262 pages
6h 59m
English
Any custom dataset class, say for example, our Dogs dataset class, has to inherit from the PyTorch dataset class. The custom class has to implement two main functions, namely __len__(self) and __getitem__(self, idx). Any custom class acting as a Dataset class should look like the following code snippet:
from torch.utils.data import Datasetclass DogsAndCatsDataset(Dataset): def __init__(self,): pass def __len__(self): pass def __getitem__(self,idx): pass
We do any initialization, if required, inside the init method—for example, reading the index of the table and reading the filenames of the images, in our case. The __len__(self) operation is responsible for returning the maximum number of elements in our dataset. The __getitem__(self, ...