In order to use this for images-
I tried this solution for images to which I got this error
File “/home/sagarbhonde/kiwi/kd/dataset.py”, line 90, in set_use_cache
self.cached_images = torch.stack(self.cached_images)
TypeError: stack(): argument ‘tensors’ (position 1) must be tuple of Tensors, not Tensor
So you might want to change set_use_cache method to:
    def set_use_cache(self, use_cache):
        if use_cache:
            x_img = tuple(self.cached_images)
            self.cached_images = torch.stack(x_img)
        else:
            self.cached_images = []
        self.use_cache = use_cache