Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix randomness for threading #7925

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions monai/transforms/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ def execute_compose(
return data

for _transform in transforms[start:end]:
if threading:
_transform = deepcopy(_transform) if isinstance(_transform, ThreadUnsafe) else _transform
if threading and isinstance(_transform, ThreadUnsafe):
if isinstance(_transform, Randomizable):
# iterate the random state before deepcopy, otherwise there is no randomness
d = dict(data) if isinstance(data, Mapping) else data
_transform.randomize(d)
_transform = deepcopy(_transform)
data = apply_transform(
_transform, data, map_items, unpack_items, lazy=lazy, overrides=overrides, log_stats=log_stats
)
Expand Down
2 changes: 1 addition & 1 deletion monai/transforms/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def randomize(self, data: Any) -> None:
Raises:
NotImplementedError: When the subclass does not override this method.
"""
raise NotImplementedError(f"Subclass {self.__class__.__name__} must implement this method.")
raise NotImplementedError(f"Subclass {self.__class__.__name__} must implement the randomize() method.")


class Transform(ABC):
Expand Down
Loading