Hello!
I’m trying to filter MNIST dataset by using a desired label using the following code:
mnist_full = datasets.MNIST(self.data_dir, train=True, transform=self.transform)
idx = mnist_full.targets == self.labels
mnist_full = mnist_full[idx]
with self.labels=1
The expected behaviour would be to obtain a dataset only with 1’s, but I get the following error:
File "/Work/vidanodet/./src/simple_GAN.py", line 55, in setup
mnist_full = mnist_full[idx]
File "/usr/local/lib/python3.9/dist-packages/torchvision/datasets/mnist.py", line 127, in __getitem__
img, target = self.data[index], int(self.targets[index])
ValueError: only one element tensors can be converted to Python scalars
I’ve checked idx is a tensor with 1 dimension containing booleans. Any idea of the problem?
Thanks!