# Buggy code
def get_subjects_iterable(self) -> Iterator:
    # I need a DataLoader to handle parallelism
    # But this loader is always expected to yield single subject samples
    self._print(f"\nCreating subjects loader with {self.num_workers} workers")
    subjects_loader = DataLoader(
        self.subjects_dataset,
        num_workers=self.num_workers,
        pin_memory=self.pin_memory,
        batch_size=1,
        collate_fn=self.get_first_item,
        shuffle=self.shuffle_subjects,
    )
    return iter(subjects_loader)


# 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 get_subjects_iterable(self) -> Iterator:
    # I need a DataLoader to handle parallelism
    # But this loader is always expected to yield single subject samples
    self._print(f"\nCreating subjects loader with {self.num_workers} workers")
    subjects_loader = DataLoader(
        self.subjects_dataset,
        num_workers=self.num_workers,
        batch_size=1,
        collate_fn=self.get_first_item,
        shuffle=self.shuffle_subjects,
    )
    return iter(subjects_loader)