Replies: 3 comments
-
that's because MONAI/monai/transforms/transform.py Lines 46 to 48 in 299f2c2 the idea is that for example in Compose([RandSpatialCropSamples(num_samples=10, ...), OtherTransform(...)] the |
Beta Was this translation helpful? Give feedback.
-
I don't think this is related to the number of samples. The same behaviour can be seen using any other random transform, e.g., import unittest
import numpy as np
from monai.data import ArrayDataset, DataLoader
from monai.transforms import Compose, RandAffine
class TestArrayDatasetTransforms(unittest.TestCase):
def test_same_transforms(self):
im = np.arange(0, 100 ** 3).reshape(1, 100, 100, 100)
a1 = [np.copy(im) for _ in range(20)]
a2 = [np.copy(im) for _ in range(20)]
t1 = Compose([RandAffine(prob=1, rotate_range=(np.pi, np.pi),
translate_range=(5, 5), as_tensor_output=False)])
t2 = RandAffine(prob=1, rotate_range=(np.pi, np.pi),
translate_range=(5, 5), as_tensor_output=False)
dataset = ArrayDataset(a1, t1, a2, t2)
dataset.set_random_state(1234)
loader = DataLoader(dataset, batch_size=2, num_workers=0)
batch_data = next(iter(loader))
np.testing.assert_array_equal(batch_data[0], batch_data[1])
if __name__ == "__main__":
unittest.main() |
Beta Was this translation helpful? Give feedback.
-
I see, the set random state method of compose adds some control of the transforms MONAI/monai/transforms/compose.py Lines 114 to 118 in a6ca680 I feel that is somehow expected, to have a sequence of random seeds for a list of transforms. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Noticed when looking into #2052.
ArrayDataset
gives matching results ifimg_transform
andlabel_transform
match each other. However results diverge when they don't match. At which point, I don't fully understand the utility of the ArrayDataset over using dictionary transforms. Perhaps I've misunderstood something.To Reproduce
The following code is fine if
t1
matchest2
, but fails if they are different.works:
doesn't work
also doesn't work
Beta Was this translation helpful? Give feedback.
All reactions