Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Iterating over PyTorch dataloader without StopIteration using try/except
batch_iterator = iter(dataloader)
images, targets = next(batch_iterator)
try:
images, targets = next(batch_iterator)
except StopIteration:
batch_iterator = iter(data_loader)
images, targets = next(batch_iterator)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment