Pytorch DataLoader output is not iterable

  dataloader, python, pytorch, torch

I am following some tutorials online about Pytorch and it seems at some point I do not get the expected output although I follow everything step by step.

import torch
import torchvision
from torchvision import datasets, transforms
Train = datasets.MNIST("", train=True, download=True, transform=transforms.Compose([transforms.ToTensor()]))
Test = datasets.MNIST("", train=False, download=True, transform=transforms.Compose([transforms.ToTensor()]))
trainset = torch.utils.data.DataLoader(Train, batch_size= 10, shuffle=True)
testset = torch.utils.data.DataLoader(Test, batch_size= 10, shuffle=True)

But then when I try to loop through trainset I receive the following error:

for ii in trainset:
    print(ii)
    break

TypeError: __array__() takes 1 positional argument but 2 were given

Can anyone tell me why do I get this error and how I can fix it?

Source: Python Questions

LEAVE A COMMENT