TypeError: 'NoneType' object is not iterable

If i am using this line of code dls = bears.dataloaders(path) then I am getting this error.

TypeError                                 Traceback (most recent call last)
Input In [20], in <cell line: 1>()
----> 1 dls = bears.dataloaders(path)

File ~\anaconda3\envs\torch\lib\site-packages\fastai\data\block.py:158, in DataBlock.dataloaders(self, source, path, verbose, **kwargs)
    152 def dataloaders(self,
    153     source, # The data source
    154     path:str='.', # Data source and default `Learner` path
    155     verbose:bool=False, # Show verbose messages
    156     **kwargs
    157 ) -> DataLoaders:
--> 158     dsets = self.datasets(source, verbose=verbose)
    159     kwargs = {**self.dls_kwargs, **kwargs, 'verbose': verbose}
    160     return dsets.dataloaders(path=path, after_item=self.item_tfms, after_batch=self.batch_tfms, **kwargs)

File ~\anaconda3\envs\torch\lib\site-packages\fastai\data\block.py:150, in DataBlock.datasets(self, source, verbose)
    148 splits = (self.splitter or RandomSplitter())(items)
    149 pv(f"{len(splits)} datasets of sizes {','.join([str(len(s)) for s in splits])}", verbose)
--> 150 return Datasets(items, tfms=self._combine_type_tfms(), splits=splits, dl_type=self.dl_type, n_inp=self.n_inp, verbose=verbose)

File ~\anaconda3\envs\torch\lib\site-packages\fastai\data\core.py:454, in Datasets.__init__(self, items, tfms, tls, n_inp, dl_type, **kwargs)
    445 def __init__(self,
    446     items:list=None, # List of items to create `Datasets`
    447     tfms:list|Pipeline=None, # List of `Transform`(s) or `Pipeline` to apply
   (...)
    451     **kwargs
    452 ):
    453     super().__init__(dl_type=dl_type)
--> 454     self.tls = L(tls if tls else [TfmdLists(items, t, **kwargs) for t in L(ifnone(tfms,[None]))])
    455     self.n_inp = ifnone(n_inp, max(1, len(self.tls)-1))

File ~\anaconda3\envs\torch\lib\site-packages\fastai\data\core.py:454, in <listcomp>(.0)
    445 def __init__(self,
    446     items:list=None, # List of items to create `Datasets`
    447     tfms:list|Pipeline=None, # List of `Transform`(s) or `Pipeline` to apply
   (...)
    451     **kwargs
    452 ):
    453     super().__init__(dl_type=dl_type)
--> 454     self.tls = L(tls if tls else [TfmdLists(items, t, **kwargs) for t in L(ifnone(tfms,[None]))])
    455     self.n_inp = ifnone(n_inp, max(1, len(self.tls)-1))

File ~\anaconda3\envs\torch\lib\site-packages\fastcore\foundation.py:98, in _L_Meta.__call__(cls, x, *args, **kwargs)
     96 def __call__(cls, x=None, *args, **kwargs):
     97     if not args and not kwargs and x is not None and isinstance(x,cls): return x
---> 98     return super().__call__(x, *args, **kwargs)

File ~\anaconda3\envs\torch\lib\site-packages\fastai\data\core.py:368, in TfmdLists.__init__(self, items, tfms, use_list, do_setup, split_idx, train_setup, splits, types, verbose, dl_type)
    366 if do_setup:
    367     pv(f"Setting up {self.tfms}", verbose)
--> 368     self.setup(train_setup=train_setup)

File ~\anaconda3\envs\torch\lib\site-packages\fastai\data\core.py:397, in TfmdLists.setup(self, train_setup)
    395         x = f(x)
    396     self.types.append(type(x))
--> 397 types = L(t if is_listy(t) else [t] for t in self.types).concat().unique()
    398 self.pretty_types = '\n'.join([f'  - {t}' for t in types])

TypeError: 'NoneType' object is not iterable

:wave: @mohitmishra Please share your terminal session or your notebook too. It helps if you first check out the examples in the book or documentation. fastai - Computer vision intro

1 Like

You don’t mention any research that you already did, so does the first item of this search help you?

yes it got solved thanks

1 Like

My problem still persists. Would u please tell me how u resolved it?

2 years and no solution?! That must be a ‘Persistent Type Error’ !