AttributeError: 'dict' object has no attribute 'check_consistent_spatial_shape' - torchio version 0.18.21
See original GitHub issue🐛Bug
When attempting to build a PyTorch dataloader for sampling patches, using the example from the torchio.data.Queue
class documentation, I get an AttributeError
when attempting to sample a single batch of patches.
This seems to exist in version 0.18.21. When I downgrade to 0.18.20, the code works as expected. I am using PyTorch version 1.7.1.
To reproduce
This is directly from the documentation.
import torch
import torchio as tio
from torch.utils.data import DataLoader
patch_size = 96
queue_length = 300
samples_per_volume = 10
sampler = tio.data.UniformSampler(patch_size)
subject = tio.datasets.Colin27()
subjects_dataset = tio.SubjectsDataset(10 * [subject])
patches_queue = tio.Queue(
subjects_dataset,
queue_length,
samples_per_volume,
sampler,
num_workers=4,
)
patches_loader = DataLoader(patches_queue, batch_size=16)
batch = next(iter(patches_loader))
Under 0.18.21 I get:
AttributeError Traceback (most recent call last)
<ipython-input-28-bf125a1bde76> in <module>
----> 1 batch = next(iter(patches_loader))
~/miniconda3/envs/master/lib/python3.7/site-packages/torch/utils/data/dataloader.py in __next__(self)
343
344 def __next__(self):
--> 345 data = self._next_data()
346 self._num_yielded += 1
347 if self._dataset_kind == _DatasetKind.Iterable and \
~/miniconda3/envs/master/lib/python3.7/site-packages/torch/utils/data/dataloader.py in _next_data(self)
383 def _next_data(self):
384 index = self._next_index() # may raise StopIteration
--> 385 data = self._dataset_fetcher.fetch(index) # may raise StopIteration
386 if self._pin_memory:
387 data = _utils.pin_memory.pin_memory(data)
~/miniconda3/envs/master/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py in fetch(self, possibly_batched_index)
42 def fetch(self, possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]
~/miniconda3/envs/master/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py in <listcomp>(.0)
42 def fetch(self, possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]
~/miniconda3/envs/master/lib/python3.7/site-packages/torchio/data/queue.py in __getitem__(self, _)
166 if not self.patches_list:
167 self._print('Patches list is empty.')
--> 168 self.fill()
169 sample_patch = self.patches_list.pop()
170 self.num_sampled_patches += 1
~/miniconda3/envs/master/lib/python3.7/site-packages/torchio/data/queue.py in fill(self)
232 subject = self.get_next_subject()
233 iterable = self.sampler(subject)
--> 234 patches = list(islice(iterable, self.samples_per_volume))
235 self.patches_list.extend(patches)
236 if self.shuffle_patches:
~/miniconda3/envs/master/lib/python3.7/site-packages/torchio/data/sampler/uniform.py in __call__(self, subject, num_patches)
24 num_patches: int = None,
25 ) -> Generator[Subject, None, None]:
---> 26 subject.check_consistent_spatial_shape()
27
28 if np.any(self.patch_size > subject.spatial_shape):
AttributeError: 'dict' object has no attribute 'check_consistent_spatial_shape'
Expected behavior
I should be able to retrieve the patches from the Colin27
subject .
Actual behavior
Throws an error
TorchIO version 0.18.21
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (7 by maintainers)
Top Results From Across the Web
python - AttributeError: 'dict' object has no attribute 'predictors'
The AttributeError is an exception thrown when an object does not have the attribute you tried to access. The class dict does not...
Read more >Attributeerror: 'Dict' Object Has No Attribute 'Save_To_Db' 0
The reason for the error message AttributeError: 'str' object has no ... object has no attribute 'checkconsistentspatialshape' torchio version 0.18.21 #431.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve disabled memory pinning in the queue, i.e., reverted some of the changes in #423. If there’s interest in memory pinning, we’ll work on that.
This error shouldn’t happen in
v0.18.22
. Thanks for reporting, @rayryeng!My pleasure! Thanks for making such an awesome set of tools for training medical models!