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,
                               torchvision.transforms.Resize(8) ]))
upscale = transforms.Compose([transforms.Resize(28)])
pil, label = dataset[0] #Take first image in dataset
result = upscale(pil)

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 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.