Last active
December 20, 2021 08:06
-
-
Save e96031413/250cd03338e64c2be099172f299fb3e9 to your computer and use it in GitHub Desktop.
Iterating over PyTorch dataloader without StopIteration using try/except
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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