Errors relating to fastai `Datasets` objects
/mnt/d/lib/python3.7/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at  /pytorch/c10/cuda/CUDAFunctions.cpp:100.)
  return torch._C._cuda_getDeviceCount() > 0

Any issues regarding the building or calling of Datasets objects will raise one of these issues to help narrow down what went wrong

TfmdLists.__init__[source]

TfmdLists.__init__(items, tfms, use_list=None, do_setup=True, split_idx=None, train_setup=True, splits=None, types=None, verbose=False, dl_type=None)

Initialize self. See help(type(self)) for accurate signature.

TfmdLists now will raise an error if items is either None or has a length of zero

As an example let's try and build a Dataset with no items:

from fastai.data.core import Datasets

dset = Datasets([])
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-7-b208b2772fe4> in <module>()
      1 from fastai.data.core import Datasets
      2 
----> 3 dset = Datasets([])

/mnt/d/lib/python3.7/site-packages/fastai/data/core.py in __init__(self, items, tfms, tls, n_inp, dl_type, **kwargs)
    308     def __init__(self, items=None, tfms=None, tls=None, n_inp=None, dl_type=None, **kwargs):
    309         super().__init__(dl_type=dl_type)
--> 310         self.tls = L(tls if tls else [TfmdLists(items, t, **kwargs) for t in L(ifnone(tfms,[None]))])
    311         self.n_inp = ifnone(n_inp, max(1, len(self.tls)-1))
    312 

/mnt/d/lib/python3.7/site-packages/fastai/data/core.py in <listcomp>(.0)
    308     def __init__(self, items=None, tfms=None, tls=None, n_inp=None, dl_type=None, **kwargs):
    309         super().__init__(dl_type=dl_type)
--> 310         self.tls = L(tls if tls else [TfmdLists(items, t, **kwargs) for t in L(ifnone(tfms,[None]))])
    311         self.n_inp = ifnone(n_inp, max(1, len(self.tls)-1))
    312 

/mnt/d/lib/python3.7/site-packages/fastcore/foundation.py in __call__(cls, x, *args, **kwargs)
     95     def __call__(cls, x=None, *args, **kwargs):
     96         if not args and not kwargs and x is not None and isinstance(x,cls): return x
---> 97         return super().__call__(x, *args, **kwargs)
     98 
     99 # Cell

<ipython-input-4-d5e948ba7242> in __init__(self, items, tfms, use_list, do_setup, split_idx, train_setup, splits, types, verbose, dl_type)
      3 def __init__(self:TfmdLists, items, tfms, use_list=None, do_setup=True, split_idx=None, train_setup=True,
      4                 splits=None, types=None, verbose=False, dl_type=None):
----> 5     if items is None or len(items) == 0: raise IndexError('Items passed in either has a length of zero or is None')
      6     super(TfmdLists, self).__init__(items, use_list=use_list)
      7     if dl_type is not None: self._dl_type = dl_type

IndexError: Items passed in either has a length of zero or is None

subset_error[source]

subset_error(e:IndexError, i:int)

IndexError when attempting to grab a non-existant subset in the dataset at index i

TfmdLists.subset[source]

TfmdLists.subset(i:int)

New TfmdLists with same tfms that only includes items in ith split

subset_error adds onto our previous IndexError, by also raising an error for when we try and grab a particular subset of the Dataset, such as dset.train, dset.valid, or dset.subset(i).

Let's look at an example below, where we only have a training dataset but no validation (as we passed no splits in)

dset = Datasets([0,1,2])
dset.valid
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-17-1922ce98bab8> in <module>()
      2 
      3 dset = Datasets([0,1,2])
----> 4 dset.valid

/mnt/d/lib/python3.7/site-packages/fastai/data/core.py in <lambda>(i, x)
    217         return self._dbunch_type(*dls, path=path, device=device)
    218 
--> 219 FilteredBase.train,FilteredBase.valid = add_props(lambda i,x: x.subset(i))
    220 
    221 # Cell

/mnt/d/lib/python3.7/site-packages/fastai/data/core.py in subset(self, i)
    321     def __repr__(self): return coll_repr(self)
    322     def decode(self, o, full=True): return tuple(tl.decode(o_, full=full) for o_,tl in zip(o,tuplify(self.tls, match=o)))
--> 323     def subset(self, i): return type(self)(tls=L(tl.subset(i) for tl in self.tls), n_inp=self.n_inp)
    324     def _new(self, items, *args, **kwargs): return super()._new(items, tfms=self.tfms, do_setup=False, **kwargs)
    325     def overlapping_splits(self): return self.tls[0].overlapping_splits()

/mnt/d/lib/python3.7/site-packages/fastcore/foundation.py in __call__(cls, x, *args, **kwargs)
     95     def __call__(cls, x=None, *args, **kwargs):
     96         if not args and not kwargs and x is not None and isinstance(x,cls): return x
---> 97         return super().__call__(x, *args, **kwargs)
     98 
     99 # Cell

/mnt/d/lib/python3.7/site-packages/fastcore/foundation.py in __init__(self, items, use_list, match, *rest)
    103     def __init__(self, items=None, *rest, use_list=False, match=None):
    104         if (use_list is not None) or not is_array(items):
--> 105             items = listify(items, *rest, use_list=use_list, match=match)
    106         super().__init__(items)
    107 

/mnt/d/lib/python3.7/site-packages/fastcore/basics.py in listify(o, use_list, match, *rest)
     54     elif isinstance(o, list): res = o
     55     elif isinstance(o, str) or is_array(o): res = [o]
---> 56     elif is_iter(o): res = list(o)
     57     else: res = [o]
     58     if match is not None:

/mnt/d/lib/python3.7/site-packages/fastai/data/core.py in <genexpr>(.0)
    321     def __repr__(self): return coll_repr(self)
    322     def decode(self, o, full=True): return tuple(tl.decode(o_, full=full) for o_,tl in zip(o,tuplify(self.tls, match=o)))
--> 323     def subset(self, i): return type(self)(tls=L(tl.subset(i) for tl in self.tls), n_inp=self.n_inp)
    324     def _new(self, items, *args, **kwargs): return super()._new(items, tfms=self.tfms, do_setup=False, **kwargs)
    325     def overlapping_splits(self): return self.tls[0].overlapping_splits()

<ipython-input-5-014fdf49d404> in subset(self, i)
     10         err += args
     11         e.args = [err]
---> 12         raise e

<ipython-input-5-014fdf49d404> in subset(self, i)
      4     "New `TfmdLists` with same tfms that only includes items in `i`th split"
      5     try:
----> 6         return self._new(self._get(self.splits[i]), split_idx=i)
      7     except IndexError as e:
      8         args = e.args[0]

/mnt/d/lib/python3.7/site-packages/fastai/data/core.py in _new(self, items, split_idx, **kwargs)
    238     def _new(self, items, split_idx=None, **kwargs):
    239         split_idx = ifnone(split_idx,self.split_idx)
--> 240         return super()._new(items, tfms=self.tfms, do_setup=False, types=self.types, split_idx=split_idx, **kwargs)
    241     def subset(self, i): return self._new(self._get(self.splits[i]), split_idx=i)
    242     def _after_item(self, o): return self.tfms(o)

/mnt/d/lib/python3.7/site-packages/fastai/data/core.py in _new(self, items, **kwargs)
    202     @property
    203     def n_subsets(self): return len(self.splits)
--> 204     def _new(self, items, **kwargs): return super()._new(items, splits=self.splits, **kwargs)
    205     def subset(self): raise NotImplemented
    206 

/mnt/d/lib/python3.7/site-packages/fastcore/foundation.py in _new(self, items, *args, **kwargs)
    108     @property
    109     def _xtra(self): return None
--> 110     def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
    111     def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)
    112     def copy(self): return self._new(self.items.copy())

/mnt/d/lib/python3.7/site-packages/fastcore/foundation.py in __call__(cls, x, *args, **kwargs)
     95     def __call__(cls, x=None, *args, **kwargs):
     96         if not args and not kwargs and x is not None and isinstance(x,cls): return x
---> 97         return super().__call__(x, *args, **kwargs)
     98 
     99 # Cell

<ipython-input-4-d5e948ba7242> in __init__(self, items, tfms, use_list, do_setup, split_idx, train_setup, splits, types, verbose, dl_type)
      3 def __init__(self:TfmdLists, items, tfms, use_list=None, do_setup=True, split_idx=None, train_setup=True,
      4                 splits=None, types=None, verbose=False, dl_type=None):
----> 5     if items is None or len(items) == 0: raise IndexError('Items passed in either has a length of zero or is None')
      6     super(TfmdLists, self).__init__(items, use_list=use_list)
      7     if dl_type is not None: self._dl_type = dl_type

IndexError: Tried to grab subset 1 in the Dataset, but it contains no items.

Items passed in either has a length of zero or is None

TfmdLists.setup[source]

TfmdLists.setup(train_setup=True)

Transform setup with self