# Buggy code
def __init__(
    self,
    subjects_dataset: SubjectsDataset,
    max_length: int,
    samples_per_volume: int,
    sampler: PatchSampler,
    num_workers: int = 0,
    pin_memory: bool = True,
    shuffle_subjects: bool = True,
    shuffle_patches: bool = True,
    start_background: bool = True,
    verbose: bool = False,
):
    self.subjects_dataset = subjects_dataset
    self.max_length = max_length
    self.shuffle_subjects = shuffle_subjects
    self.shuffle_patches = shuffle_patches
    self.samples_per_volume = samples_per_volume
    self.sampler = sampler
    self.num_workers = num_workers
    self.pin_memory = pin_memory
    self.verbose = verbose
    self._subjects_iterable = None
    if start_background:
        self.initialize_subjects_iterable()
    self.patches_list: List[Subject] = []
    self.num_sampled_patches = 0


# Traceback (AttributeError)
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'

# Fixed code
def __init__(
    self,
    subjects_dataset: SubjectsDataset,
    max_length: int,
    samples_per_volume: int,
    sampler: PatchSampler,
    num_workers: int = 0,
    shuffle_subjects: bool = True,
    shuffle_patches: bool = True,
    start_background: bool = True,
    verbose: bool = False,
):
    self.subjects_dataset = subjects_dataset
    self.max_length = max_length
    self.shuffle_subjects = shuffle_subjects
    self.shuffle_patches = shuffle_patches
    self.samples_per_volume = samples_per_volume
    self.sampler = sampler
    self.num_workers = num_workers
    self.verbose = verbose
    self._subjects_iterable = None
    if start_background:
        self.initialize_subjects_iterable()
    self.patches_list: List[Subject] = []
    self.num_sampled_patches = 0