Skip to content

Instantly share code, notes, and snippets.

@e96031413
Last active December 20, 2021 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e96031413/250cd03338e64c2be099172f299fb3e9 to your computer and use it in GitHub Desktop.
Save e96031413/250cd03338e64c2be099172f299fb3e9 to your computer and use it in GitHub Desktop.
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