Skip to content

Commit ce4360c

Browse files
committed
Slight fix to how epoch length is guessed
Signed-off-by: Eric Kerfoot <[email protected]>
1 parent 97dd0df commit ce4360c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

monai/engines/workflow.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ def __init__(
133133
def set_sampler_epoch(engine: Engine) -> None:
134134
sampler.set_epoch(engine.state.epoch)
135135

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

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

0 commit comments

Comments
 (0)