Load the whole dataset in RAM

Yes you could use this:

Will lazy load the images into a dict and speeds up epoch time.

class MemoryImageList(ImageList):
    _map = {}
    def open(self, i):
        item = self._map.get(str(i))
        if isinstance(item, Image):
            return item
        item = super().open(i)
        self._map[str(i)] = item
        return item
data = MemoryImageList.from_folder(untar_data(URLs.MNIST)/'training').split_by_rand_pct(.2, seed=1).label_from_folder().databunch(bs=128).normalize(imagenet_stats)
learn = cnn_learner(data, models.resnet18, metrics=accuracy)
learn.fit_one_cycle(3)

Demo Notebook

4 Likes