Resize multiple times with torchvision

I’m looking to resize the MNIST dataset to a 8x8 image, and then resize the 8x8 image, back to its original dimensions. During this process, the image should lose quality (since we are resizing from 8x8 to 28x28.

Currently, the code is as follows

dataset = torchvision.datasets.MNIST('./', train=True, download=False,
                             transform=torchvision.transforms.Compose([
                               torchvision.transforms.Resize(8) ]))
upscale = transforms.Compose([transforms.Resize(28)])
pil, label = dataset[0] #Take first image in dataset
result = upscale(pil)
result.show()

But this does not save the result into the MNIST object (i.e. the variable named "dataset’). I would also need a nasty for loop to loop through all the images.

Is there a better way to accomplish this?

Since the MNIST data is preloaded completely, you could directly access it via dataset.data and apply the resizing on this tensor directly.
However, if you are working with a dataset, which uses lazy loading, you would have to iterate the dataset, as each sample is loaded in the corresponding iteration.