How to save MNIST as jpg files

(LIN_MG) #1

Hi, all

How to save MNIST as .jpg format ?
Is it possible with
from torchvision.utils import save_image?

(I use default dataloader from pytorch.)


Since the torchvision.datasets.MNIST dataset returns PIL Images, if you don’t specify a transformation, the easiest way would be to directly save them:

dataset = datasets.MNIST(root=PATH)

for idx, (img, _) in enumerate(dataset):'{:05d}.jpg'.format(idx))