Closed jcohenadad closed 1 year ago
However, when trying , it does not select slices with labels anymore. So, I'm trying to figure out how patches are organized.
When removing intensity scaling, and batch_size=1, I can figure out that each patch corresponds to a z-slice, and the [0,0] voxel is identified:
Working prototype at 66bdb42332e4cda5b10996ce96e838c40a9fc4db using PatchDataset
and custom patch_func
Alternative approach in 375bdf53ddbc8c5ef7b7544403b64122946d7565
Working code in https://github.com/ivadomed/model_seg_mouse-sc_wm-gm_t1/pull/1 🎉
Alternative approach suggested in https://github.com/Project-MONAI/MONAI/discussions/5948#discussioncomment-5330042
While debugging, I can see the error is related to a mismatch between the extracted label and the input size:
Trying https://github.com/Project-MONAI/MONAI/discussions/5948#discussioncomment-5346854 in 5107b4181a018358e43b34f1189819a6ce042b88, getting:
Traceback (most recent call last):
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/monai/transforms/transform.py", line 103, in apply_transform
return _apply_transform(transform, data, unpack_items)
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/monai/transforms/transform.py", line 67, in _apply_transform
return transform(parameters)
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/monai/transforms/utility/array.py", line 262, in __call__
raise ValueError(msg)
ValueError: Metadata not available and channel_dim=None, EnsureChannelFirst is not in use.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<input>", line 1, in <module>
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/monai/utils/misc.py", line 105, in first
for i in iterable:
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 628, in __next__
data = self._next_data()
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 671, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 58, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 58, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/monai/data/dataset.py", line 110, in __getitem__
return self._transform(index)
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/monai/data/grid_dataset.py", line 270, in _transform
patches = self.patch_func(image)
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/monai/transforms/compose.py", line 177, in __call__
input_ = apply_transform(_transform, input_, self.map_items, self.unpack_items, self.log_stats)
File "/Users/julien/code/model_seg_mouse-sc_wm-gm_t1/venv/lib/python3.10/site-packages/monai/transforms/transform.py", line 130, in apply_transform
raise RuntimeError(f"applying transform {transform}") from e
RuntimeError: applying transform <monai.transforms.utility.array.EnsureChannelFirst object at 0x7f9355f669e0>
Issue was fixed in 4042dc744c74c08b0e05976b513b1bb8c1b1de50 (thank you @KumoLiu):
Can close
See this tutorial, notably the 'squeeze dim', which I am currently not doing.
Useful links:
With the current code, I am able to get 2D patches, only those that contain a non-empty label slice: