Error: 'DataLoaderIter' object has no attribute 'shutdown'

Traceback (most recent call last):
File “”, line 55, in
for iteration, batch in enumerate(data_loader):
File “/home/vishal/anaconda3/lib/python3.6/site-packages/torch/utils/data/”, line 251, in iter
return DataLoaderIter(self)
File “/home/vishal/anaconda3/lib/python3.6/site-packages/torch/utils/data/”, line 103, in init
self.sample_iter = iter(self.sampler)
File “/home/vishal/anaconda3/lib/python3.6/site-packages/torch/utils/data/”, line 50, in iter
return iter(torch.randperm(self.num_samples).long())
RuntimeError: must be strictly positive at /home/soumith/local/builder/wheel/pytorch-src/torch/lib/TH/generic/THTensorMath.c:1473
Exception ignored in: <bound method DataLoaderIter.del of < object at 0x7fc28cc66898>>
Traceback (most recent call last):
File “/home/vishal/anaconda3/lib/python3.6/site-packages/torch/utils/data/”, line 212, in del
File “/home/vishal/anaconda3/lib/python3.6/site-packages/torch/utils/data/”, line 204, in _shutdown_workers
if not self.shutdown:
AttributeError: ‘DataLoaderIter’ object has no attribute ‘shutdown’

Without any context, we cannot reply with an answer. What are you looking for, is there a script to reproduce this error?

I am trying to implemen fast neural style. The training function is here

for epoch in range(args.epochs):
    for iteration, batch in enumerate(data_loader):
        x = Variable(batch[0])
        x = batch_rgb_to_bgr(x)
        if args.cuda:
            x = x.cuda()
        y_hat = model(x)
        xc = Variable(x.clone())
        loss = loss_function(args.content_weight, args.style_weight, xc, xs, y_hat)
        print("===> Epoch[{}]({}/{}): Loss: {:.4f}".format(epoch, iteration, len(data_loader),[0])), 'model_{}.pth'.format(epoch)), 'model.pth')

and the dataloader code

train_set = datasets.ImageFolder(args.dataset_path, transform)
data_loader = DataLoader(dataset=train_set, num_workers=args.threads, batch_size=args.batchSize, shuffle=True)

The problem is that your train_set has 0 images.
I’ve figured it out from this part of your error:
RuntimeError: must be strictly positive at /home/soumith/local/builder/wheel/pytorch-src/torch/lib/TH/generic/THTensorMath.c:1473

You can check this by doing:


datasets.ImageFolder will pick up all images from subfolders of dataset_path, but not in the root directory of dataset_path itself. Maybe that’s your mistake?
for example if dataset_path has:


ImageFolder will have length=2 and will have 2 classes ['cat', 'dog'] with indices [0, 1] and will have two images b.png, c.png in it.

It will not have a.png

Also, another thing – ImageFolder will only pick up the following image extensions:

Hope that helps figure out your issue.