DataBunch randomly fails to load batches

I’m trying to reimplement the pascal-multi.ipynb from Fastai v0.7 to Fastai v1, however I’m stuck just trying to get batches to load consistently. Training will run for a few batches and then fail with this error about a 0-d tensor. It seems random, and I’ve narrowed it down to the DataBunch class. Any ideas why this might be happening? Here’s the error I get:

~/miniconda3/envs/yolo/lib/python3.7/site-packages/fastai/basic_data.py in __iter__(self)
     68     def __iter__(self):
     69         "Process and returns items from `DataLoader`."
---> 70         for b in self.dl: yield self.proc_batch(b)
     71 
     72     @classmethod

~/miniconda3/envs/yolo/lib/python3.7/site-packages/torch/utils/data/dataloader.py in __next__(self)
    613         if self.num_workers == 0:  # same-process loading
    614             indices = next(self.sample_iter)  # may raise StopIteration
--> 615             batch = self.collate_fn([self.dataset[i] for i in indices])
    616             if self.pin_memory:
    617                 batch = pin_memory_batch(batch)

~/miniconda3/envs/yolo/lib/python3.7/site-packages/fastai/vision/data.py in bb_pad_collate(samples, pad_idx)
     40 def bb_pad_collate(samples:BatchSamples, pad_idx:int=0) -> Tuple[FloatTensor, Tuple[LongTensor, LongTensor]]:
     41     "Function that collect `samples` of labelled bboxes and adds padding with `pad_idx`."
---> 42     max_len = max([len(s[1].data[1]) for s in samples])
     43     bboxes = torch.zeros(len(samples), max_len, 4)
     44     labels = torch.zeros(len(samples), max_len).long() + pad_idx

~/miniconda3/envs/yolo/lib/python3.7/site-packages/fastai/vision/data.py in <listcomp>(.0)
     40 def bb_pad_collate(samples:BatchSamples, pad_idx:int=0) -> Tuple[FloatTensor, Tuple[LongTensor, LongTensor]]:
     41     "Function that collect `samples` of labelled bboxes and adds padding with `pad_idx`."
---> 42     max_len = max([len(s[1].data[1]) for s in samples])
     43     bboxes = torch.zeros(len(samples), max_len, 4)
     44     labels = torch.zeros(len(samples), max_len).long() + pad_idx

~/miniconda3/envs/yolo/lib/python3.7/site-packages/torch/tensor.py in __len__(self)
    409     def __len__(self):
    410         if self.dim() == 0:
--> 411             raise TypeError("len() of a 0-d tensor")
    412         return self.shape[0]
    413 

TypeError: len() of a 0-d tensor
1 Like