Skip to content

Commit

Permalink
Slight fix to how epoch length is guessed
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Kerfoot <eric.kerfoot@kcl.ac.uk>
  • Loading branch information
ericspod committed Dec 18, 2024
1 parent 97dd0df commit ce4360c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions monai/engines/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ def __init__(
def set_sampler_epoch(engine: Engine) -> None:
sampler.set_epoch(engine.state.epoch)

# if the epoch_length isn't given, attempt to get it from the length of the data loader
if epoch_length is None and isinstance(data_loader.dataset, Sized):
epoch_length = len(data_loader.dataset)
# if the epoch_length isn't given, attempt to get it from the length of the data loader
if epoch_length is None and isinstance(data_loader, Sized):
try:
epoch_length = len(data_loader)
except TypeError: # raised when data_loader has an iterable dataset with no length, or is some other type
pass # deliberately leave epoch_length as None

# set all sharable data for the workflow based on Ignite engine.state
self.state: Any = State(
Expand Down

0 comments on commit ce4360c

Please sign in to comment.