Does iterated composition work as expected? #6172
-
I am just curious, if monai.transforms.Compose([
monai.transforms.Compose([t1, t2]),
monai.transforms.Compose([t3, t4]),
]) to behave exactly the same as monai.transforms.Compose([t1, t2, t3, t4]) in every way? Will there be different caching behavior if, for example, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Hi @ebrahimebrahim, I don't understand what the purpose of your Lines 883 to 884 in baa17a8 MONAI/monai/transforms/compose.py Line 40 in baa17a8 Hope it can help you, thanks! |
Beta Was this translation helpful? Give feedback.
-
I was just bitten by class Base(pl.LightningModule):
self.common_transforms = Compose(
[
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
NormalizeIntensityd(keys=["image"]),
LabelFilterd(keys="label", ...),
]
)
class VariantOne(Base):
self.train_transforms = Compose([self.common_transforms, RandSpatialCropd(...), ...])
class VariantTwo(Base):
self.train_transforms = Compose([self.common_transforms, RandSpatialCropd(...), ...]) The above is a lot slower (approx. 10x in my case) to train than this: class VariantX(Base):
self.train_transforms = Compose([*self.common_transforms.transforms, RandSpatialCropd(...), ...]) The difference is using |
Beta Was this translation helpful? Give feedback.
-
currently |
Beta Was this translation helpful? Give feedback.
-
Hi folks. I've spent some time thinking about this during some refactoring earlier this year and I've opened issue #7130 with a corresponding draft PR #7131. I think there is a good opportunity here to both resolve this issue and also resolve other incongruencies that occur with nested Composes. Please take a look |
Beta Was this translation helpful? Give feedback.
Hi @ebrahimebrahim, I don't understand what the purpose of your
Compose
inCompose
is.CacheDataset
will only cache deterministic transforms' results during training andCompose
is inherited fromCompose
, it may have some issues when caching.MONAI/monai/data/dataset.py
Lines 883 to 884 in baa17a8
MONAI/monai/transforms/compose.py
Line 40 in baa17a8
Hope it can help you, thanks!