From fa4ceb7d97029437aad344269a4cc99196219ba3 Mon Sep 17 00:00:00 2001 From: "marcus.wirtz" Date: Wed, 17 Jul 2024 14:21:20 +0200 Subject: [PATCH] Fix randomness for threading --- monai/transforms/compose.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/monai/transforms/compose.py b/monai/transforms/compose.py index 236d3cc4c51..fe664907bc8 100644 --- a/monai/transforms/compose.py +++ b/monai/transforms/compose.py @@ -107,7 +107,11 @@ def execute_compose( for _transform in transforms[start:end]: if threading: - _transform = deepcopy(_transform) if isinstance(_transform, ThreadUnsafe) else _transform + if isinstance(_transform, ThreadUnsafe): + if isinstance(_transform, Randomizable): + # update the random state before deepcopy, otherwise there is no randomness + _transform.randomize() + _transform = deepcopy(_transform) data = apply_transform( _transform, data, map_items, unpack_items, lazy=lazy, overrides=overrides, log_stats=log_stats )