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)

print(loader.dataset)
# > <torch.utils.data.dataset.TensorDataset object at 0x7fd40071a9a0>

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