Skip to content

Commit

Permalink
Trying a better way of getting length
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Kerfoot <eric.kerfoot@gmail>
  • Loading branch information
Eric Kerfoot committed Dec 18, 2024
1 parent 10d8c9a commit aac82f5
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions monai/engines/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import warnings
from collections.abc import Callable, Iterable, Sequence
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Sized

import torch
import torch.distributed as dist
Expand Down Expand Up @@ -133,12 +133,9 @@ 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:
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
# 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)

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

0 comments on commit aac82f5

Please sign in to comment.