Slicing/selecting tensors from a dataset?

Hi all, I’m working with the MNIST dataset available through torchvision and am trying to visualize the data (average digit, overlaid digits, etc.). While I am able extract/transform/load the dataset I can’t seem to find a way to extract the data itself to perform operations such as slicing and subsetting.

Any clarification would be greatly appreciated!

You could access the underlying .data and .target attributes:

import torchvision.transforms.functional as TF

dataset = datasets.MNIST(root='./data',
                         transform=transforms.ToTensor())
data = dataset.data
print(data.shape) # torch.Size([60000, 28, 28])
img = TF.to_pil_image(data[0])
1 Like