-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
Transforms that produce images of variable size are incompatible with default collator, since this expects all images to be the same size.
Examples that I've found so far are (I guess same would apply to array versions)):
RandSpatialCropd(withrandom_size==True)RandRotated(withkeep_size==False)RandZoomd(withkeep_size==False)RandRotate90d(if input wasn't square/cubic)
You wouldn't see this problem if you a) specify some custom collator, or b) followed up these transforms with other transforms that unified image shape (e.g., SpatialPadd). I can't imagine many people do the former, and for the latter I don't see the utility of allowing the image size to change if you are then going to crop/pad back to a fixed size.
Unless I've mistaken something, I suggest removing functionality that could result in images inside the same batch having different sizes.
To Reproduce
import numpy as np
from monai.data import CacheDataset, DataLoader
from monai.transforms import RandSpatialCropd, RandRotated
im = np.arange(0, 10 * 9).reshape(1, 10, 9)
data = [{"image": im} for _ in range(2)]
# alternate commenting these two lines
transform = RandSpatialCropd("image", roi_size=[8, 7], random_size=True)
transform = RandRotated("image", prob=1, range_x=np.pi, keep_size=False)
dataset = CacheDataset(data, transform)
loader = DataLoader(dataset, batch_size=2)
for _ in loader:
passExample error:
stack expects each tensor to be equal size, but got [1, 13, 13] at entry 0 and [1, 10, 11] at entry 1
File "/Users/rich/Documents/Code/MONAI/monai/data/utils.py", line 245, in list_data_collate
return default_collate(data)
File "/Users/rich/Desktop/text.py", line 14, in <module>
for _ in loader: