In what condition the dataloader would raise stopiteration

I am using pytorch 0.3.0.post4. I try to train a ssd model on coco using codes from this repo and I get this stopiteration stuff and following messages after around 1000 iterations. I was wondering what would cause this problem and is there any idea to solve it?

File “”, line 255, in
File “”, line 165, in train
images, targets = next(batch_iterator)
File “/home/rusu5516/.local/lib/python3.5/site-packages/torch/utils/data/”, line 200, in next
raise StopIteration

In Python, when an iterable ends, it will raise StopIteration.

That’s because the dataloader finished iterating once over the whole dataset.

You can make a iteration cycle to avoid this:

def cycle(iterable):
    while True:
        for x in iterable:
            yield x


batch_iterator =iter(cycle(data_loader))