Project-MONAI / Project-MONAI/MONAI
RandSpatialCropSamplesd
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 8.7k
- Forks
- 1.6k
- Merge moyen
- 5 j 1 h
- PR mergées (30 j)
- 20
Description
Hi,I want to use batch_size = 2 for training. When using CenterSpatialCropd(keys=["image", "label"],roi_size=(224, 224, 224)), I can train the network, but when I use RandSpatialCropSamplesd(keys=["image", "label"],roi_size=(224, 224, 224), random_size=False, num_samples=2),ResizeWithPadOrCropd( keys=["image", "label"], spatial_size=224, mode='constant', ), the following error occurred.
collate/stack a list of tensors
E: stack expects each tensor to be equal size, but got [1, 275, 386, 386] at entry 0 and [1, 275, 380, 380] at entry 2, shape [torch.Size([1, 275, 386, 386]), torch.Size([1, 275, 386, 386]), torch.Size([1, 275, 380, 380]), torch.Size([1, 275, 380, 380])] in collate([tensor([[[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
...,
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]]]]), tensor([[[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
...,
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]]]]), tensor([[[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
...,
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]]]]), tensor([[[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
...,
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]]]])])
collate dict key "image_meta_dict" out of 4 keys
collate dict key "sizeof_hdr" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "extents" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "session_error" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "dim_info" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "dim" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "intent_p1" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "intent_p2" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "intent_p3" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "intent_code" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "datatype" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "bitpix" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "slice_start" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "pixdim" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "vox_offset" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "scl_slope" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "scl_inter" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "slice_end" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "slice_code" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "xyzt_units" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "cal_max" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "cal_min" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "slice_duration" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "toffset" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "glmax" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "glmin" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "qform_code" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "sform_code" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "quatern_b" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "quatern_c" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "quatern_d" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "qoffset_x" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "qoffset_y" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "qoffset_z" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "srow_x" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "srow_y" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "srow_z" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "affine" out of 43 keys
collate/stack a list of tensors
collate dict key "original_affine" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "as_closest_canonical" out of 43 keys
collate dict key "spatial_shape" out of 43 keys
collate/stack a list of numpy arrays
collate/stack a list of tensors
collate dict key "space" out of 43 keys
collate dict key "original_channel_dim" out of 43 keys
collate dict key "filename_or_obj" out of 43 keys
Traceback (most recent call last):
File "/mnt/store/zhengsch/Ostia_landmark/tools/train.py", line 572, in
Trainer().run()
File "/mnt/store/zhengsch/Ostia_landmark/tools/train.py", line 332, in run
self.train_step(epoch)
File "/mnt/store/zhengsch/Ostia_landmark/tools/train.py", line 392, in train_step
for i, batch_data in enumerate(self.trn_dl):
File "/opt/miniforge3/envs/monai/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 681, in next
data = self._next_data()
File "/opt/miniforge3/envs/monai/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 1376, in _next_data
return self._process_data(data)
File "/opt/miniforge3/envs/monai/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 1402, in _process_data
data.reraise()
File "/opt/miniforge3/envs/monai/lib/python3.9/site-packages/torch/_utils.py", line 461, in reraise
raise exception
RuntimeError: Caught RuntimeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/zhengsch/.local/lib/python3.9/site-packages/monai/data/utils.py", line 516, in list_data_collate
ret = collate_fn(data)
File "/home/zhengsch/.local/lib/python3.9/site-packages/monai/data/utils.py", line 478, in collate_meta_tensor
return {k: collate_meta_tensor([d[k] for d in batch]) for k in elem_0}
File "/home/zhengsch/.local/lib/python3.9/site-packages/monai/data/utils.py", line 478, in
return {k: collate_meta_tensor([d[k] for d in batch]) for k in elem_0}
File "/home/zhengsch/.local/lib/python3.9/site-packages/monai/data/utils.py", line 483, in collate_meta_tensor
return default_collate(batch)
File "/opt/miniforge3/envs/monai/lib/python3.9/site-packages/torch/utils/data/utils/collate.py", line 140, in default_collate
out = elem.new(storage).resize(len(batch), *list(elem.size()))
RuntimeError: Trying to resize storage that is not resizable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/miniforge3/envs/monai/lib/python3.9/site-packages/torch/utils/data/_utils/worker.py", line 302, in _worker_loop
data = fetcher.fetch(index)
File "/opt/miniforge3/envs/monai/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
return self.collate_fn(data)
File "/home/zhengsch/.local/lib/python3.9/site-packages/monai/data/utils.py", line 696, in pad_list_data_collate
return PadListDataCollate(method=method, mode=mode, **kwargs)(batch)
File "/home/zhengsch/.local/lib/python3.9/site-packages/monai/transforms/croppad/batch.py", line 114, in call
return list_data_collate(batch)
File "/home/zhengsch/.local/lib/python3.9/site-packages/monai/data/utils.py", line 529, in list_data_collate
raise RuntimeError(re_str) from re
RuntimeError: Trying to resize storage that is not resizable
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Reproduisez le pipeline signalé à l’aide de RandSpatialCropSamplesd, ResizeWithPadOrCropd et batch_size=2, puis examinez l’erreur de collate et les différentes formes des tenseurs. Déterminez le comportement attendu des sorties échantillonnées et vérifiez que la configuration de batch signalée produit soit des tenseurs de formes cohérentes, soit est clairement documentée comme non prise en charge.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python, pytorch
- Domaine
- data, machine-learning
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100