How to convert mnist images to variables images and labels

I have a code as below:

dataset = MNIST(path=data_path, download=True, shuffle=True)

if train:
    images, labels = dataset.get_train()
    images, labels = dataset.get_test()

images, labels = images[:n_examples], labels[:n_examples]
images, labels = iter(images.view(-1, 784) / 255), iter(labels)

but when i run it, it gives me this error

Traceback (most recent call last):
  File "C:\Users\Ati\Downloads\Compressed\bindsnet_experiments-master\experiments\mnist\", line 135, in <module>
    images, labels = dataset.get_train()
AttributeError: 'TorchvisionDatasetWrapper' object has no attribute 'get_train'

I think because get_train() is out of date , it doesn’t support by torchvision
But i tested different ways for converting mnist data to images and labels variables
Who knows how could i change it when get_train() doesn’t work
I will appreciate your help if someone helps me on this

You could access the underlying data and targets using:

Where did you see the get_train method?

1 Like

Hey…thank you for your response and yeah it did work:smiley::smiley::smiley:
I got that from this link