Dataloader has no attribute dataset

I’m running a code that uses dataloader.dataset. The original code is designed to run on Pytorch 1.1, but my Pytorch version is higher. Are there any alternatives to this attribute?

And here’s the error report.
AttributeError: '_SingleProcessDataLoaderIter' object has no attribute 'dataset'

Based on the error message it seems you are trying to access the internal .dataset attribute in the iterator, not the DataLoader itself as seen here:

dataset = TensorDataset(torch.randn(100, 1), torch.randn(100, 1))
loader = DataLoader(dataset)

# > < object at 0x7fd40071a9a0>

loader_iter = iter(loader)
# > AttributeError: '_SingleProcessDataLoaderIter' object has no attribute 'dataset'

Is there an easy way to retreive the data from the dataset/dataloader now?
Sample code from Official PyTorch Tutorial directly fails with this ERROR message:

AttributeError: '_SingleProcessDataLoaderIter' object has no attribute 'dataset' .

If the following snippet code ONLY bings trouble, why it’s ALWAYS there on the official website? Any update to make sure it’s runnable?

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

The posted code snippet it not accessing the .dataset attribute so I’m unsure how this error can even be raised.
The tutorial works fine for me, so please post a minimal, executable code snippet to reproduce the issue.

Okay… I got it… It looks to me a kind of weird…

images, labels = next(iter(validation_loader)) is working properly, however,

dataiter = iter(train_loader)
images, labels =

is not…


dataiter = iter(train_loader)
images, labels = next(dataiter)

also works… :slight_smile:

Both approaches work for me, so it’s still unclear which change in your code causes the issue.

Does it have something to do with:

I built the NEWEST PyTorch from source ? it’s showing the version: 1.13.0

I doubt it, as I’m also using a (quite new) source build, so please feel free to point to the line of code in the tutorial creating the issue (I cannot reproduce it) or post a code snippet which would raise the error.