Pytorch tutorial - Training a classifier : TypeError with Dataloader on pytorch classifier with CIFAR 10 dataset

I’m using Pytorch version 1.1.0 installed with library and trying to get to know more about the framework about how it works.

I’ve been going through the blitz tutorial and on the one with training a classifier with CIFAR10 dataset, I’m stuck at a certain point where we use the Data Loader on the training sample :

# get some random training images
dataiter = iter(trainloader)
images, labels =

When I want to run this code, it gives me the following error :

TypeError: object() takes no parameters

I don’t understand why it does this error, I’ve tried to uninstall and re-install yet it still keep doing the same error

Welcome to the PyTorch community! :smile_cat:

It’s a bit hard to tell the context without seeing the rest of your code. Also, I’m not sure what kind of wrapping has done, but this could be coming from their library.

The typical way to interact with datasets in PyTorch looks like something like this:

>>> mnist = MNIST(r"some root directory", download=True, train=True, transform=ToTensor())
>>> data = DataLoader(mnist)
>>> for num, (input, label) in enumerate(data):
...     print(num)

data in this case, an instance of the DataLoader class is itself an iterator. You can use normal python looping constructs on this. You shouldn’t have to call .next() directly.

1 Like

Thank you for your answer!
The code comes from the official PyTorch training a classifier tutorial here

EDIT : Just found the mistake…

In the code below, I’ve not put “()” after the function ToTensor

transform = transforms.Compose([transforms.ToTensor, 
                               transforms.Normalize((0.5,0.5,0.5), (0.5,0.5,0.5))])

Which led to the TypeError. But I’ve got confused as the error pointed at the lines I’ve mentioned before on my first post.

Sorry for the inconvenience and thank you for your answer!

1 Like