Errors and exceptions for any step of the `DataLoader` process
/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

This includes after_item, after_batch, and collating. Anything in relation to the Datasets or anything before the DataLoader process can be found in fastdebug.fastai.dataset

collate_error[source]

collate_error(e:Exception, batch)

Raises an explicit error when the batch could not collate, stating what items in the batch are different sizes and their types

DataLoader.create_batch[source]

DataLoader.create_batch(b)

Collate a list of items into a batch.

collate_error is @patch'd into DataLoader's create_batch function through importing this module, so if there is any possible reason why the data cannot be collated into the batch, it is presented to the user.

An example is below, where we forgot to include an item transform that resizes all our images to the same size:

from fastai.vision.all import *
path = untar_data(URLs.PETS)/'images'
dls = ImageDataLoaders.from_name_func(
    path, get_image_files(path), valid_pct=0.2,
    label_func=lambda x: x[0].isupper())

x,y = dls.train.one_batch()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-8-c493bee87237> in <module>()
      6     label_func=lambda x: x[0].isupper())
      7 
----> 8 x,y = dls.train.one_batch()

/usr/local/lib/python3.7/dist-packages/fastai/data/load.py in one_batch(self)
    148     def one_batch(self):
    149         if self.n is not None and len(self)==0: raise ValueError(f'This DataLoader does not contain any batches')
--> 150         with self.fake_l.no_multiproc(): res = first(self)
    151         if hasattr(self, 'it'): delattr(self, 'it')
    152         return res

/usr/local/lib/python3.7/dist-packages/fastcore/basics.py in first(x, f, negate, **kwargs)
    545     x = iter(x)
    546     if f: x = filter_ex(x, f=f, negate=negate, gen=True, **kwargs)
--> 547     return next(x, None)
    548 
    549 # Cell

/usr/local/lib/python3.7/dist-packages/fastai/data/load.py in __iter__(self)
    107         self.before_iter()
    108         self.__idxs=self.get_idxs() # called in context of main process (not workers/subprocesses)
--> 109         for b in _loaders[self.fake_l.num_workers==0](self.fake_l):
    110             # fix issue 2899. If the process start method isn't fork, the data will be copied to cuda in learner one_batch.
    111             if self.device is not None and multiprocessing.get_start_method().lower() == "fork":

/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py in __next__(self)
    433         if self._sampler_iter is None:
    434             self._reset()
--> 435         data = self._next_data()
    436         self._num_yielded += 1
    437         if self._dataset_kind == _DatasetKind.Iterable and \

/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py in _next_data(self)
    473     def _next_data(self):
    474         index = self._next_index()  # may raise StopIteration
--> 475         data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
    476         if self._pin_memory:
    477             data = _utils.pin_memory.pin_memory(data)

/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py in fetch(self, possibly_batched_index)
     32                 raise StopIteration
     33         else:
---> 34             data = next(self.dataset_iter)
     35         return self.collate_fn(data)
     36 

/usr/local/lib/python3.7/dist-packages/fastai/data/load.py in create_batches(self, samps)
    118         if self.dataset is not None: self.it = iter(self.dataset)
    119         res = filter(lambda o:o is not None, map(self.do_item, samps))
--> 120         yield from map(self.do_batch, self.chunkify(res))
    121 
    122     def new(self, dataset=None, cls=None, **kwargs):

/usr/local/lib/python3.7/dist-packages/fastai/data/load.py in do_batch(self, b)
    144         else: raise IndexError("Cannot index an iterable dataset numerically - must use `None`.")
    145     def create_batch(self, b): return (fa_collate,fa_convert)[self.prebatched](b)
--> 146     def do_batch(self, b): return self.retain(self.create_batch(self.before_batch(b)), b)
    147     def to(self, device): self.device = device
    148     def one_batch(self):

<ipython-input-7-a9809be51294> in create_batch(self, b)
      8     except Exception as e:
      9         if not self.prebatched:
---> 10             collate_error(e, b)
     11         else: raise e

<ipython-input-6-f0b390dbe89c> in collate_error(e, batch)
     23                     err += f'Please include a transform in `after_item` that ensures all data of type {type_a} is the same size'
     24                     e.args = [err]
---> 25                     raise e

<ipython-input-7-a9809be51294> in create_batch(self, b)
      5     func = (fa_collate,fa_convert)[self.prebatched]
      6     try:
----> 7         return func(b)
      8     except Exception as e:
      9         if not self.prebatched:

/usr/local/lib/python3.7/dist-packages/fastai/data/load.py in fa_collate(t)
     48     b = t[0]
     49     return (default_collate(t) if isinstance(b, _collate_types)
---> 50             else type(t[0])([fa_collate(s) for s in zip(*t)]) if isinstance(b, Sequence)
     51             else default_collate(t))
     52 

/usr/local/lib/python3.7/dist-packages/fastai/data/load.py in <listcomp>(.0)
     48     b = t[0]
     49     return (default_collate(t) if isinstance(b, _collate_types)
---> 50             else type(t[0])([fa_collate(s) for s in zip(*t)]) if isinstance(b, Sequence)
     51             else default_collate(t))
     52 

/usr/local/lib/python3.7/dist-packages/fastai/data/load.py in fa_collate(t)
     47     "A replacement for PyTorch `default_collate` which maintains types and handles `Sequence`s"
     48     b = t[0]
---> 49     return (default_collate(t) if isinstance(b, _collate_types)
     50             else type(t[0])([fa_collate(s) for s in zip(*t)]) if isinstance(b, Sequence)
     51             else default_collate(t))

/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/collate.py in default_collate(batch)
     53             storage = elem.storage()._new_shared(numel)
     54             out = elem.new(storage)
---> 55         return torch.stack(batch, 0, out=out)
     56     elif elem_type.__module__ == 'numpy' and elem_type.__name__ != 'str_' \
     57             and elem_type.__name__ != 'string_':

/usr/local/lib/python3.7/dist-packages/fastai/torch_core.py in __torch_function__(self, func, types, args, kwargs)
    327         convert=False
    328         if _torch_handled(args, self._opt, func): convert,types = type(self),(torch.Tensor,)
--> 329         res = super().__torch_function__(func, types, args=args, kwargs=kwargs)
    330         if convert: res = convert(res)
    331         if isinstance(res, TensorBase): res.set_meta(self, as_copy=True)

/usr/local/lib/python3.7/dist-packages/torch/tensor.py in __torch_function__(cls, func, types, args, kwargs)
    993 
    994         with _C.DisableTorchFunction():
--> 995             ret = func(*args, **kwargs)
    996             return _convert(ret, cls)
    997 

RuntimeError: Error when trying to collate the data into batches with fa_collate, at least two tensors in the batch are not the same size.

Mismatch found within the 0th axis of the batch and is of type TensorImage:
The first item has shape: torch.Size([3, 500, 333])
The second item has shape: torch.Size([3, 333, 500])

Please include a transform in `after_item` that ensures all data of type TensorImage is the same size

TfmdDL.new[source]

TfmdDL.new(dataset=None)

Create a new version of self with a few changed attributes