then you also need to write your collate_fn

  
      github.com
  
  
    pytorch/pytorch/blob/master/torch/utils/data/dataloader.py#L83 38

        raise
    if r is None:
        break
    if isinstance(r[1], ExceptionWrapper):
        out_queue.put(r)
        continue
    idx, batch = r
    try:
        if pin_memory:
            batch = pin_memory_batch(batch)
    except Exception:
        out_queue.put((idx, ExceptionWrapper(sys.exc_info())))
    else:
        out_queue.put((idx, batch))


numpy_type_map = {
'float64': torch.DoubleTensor,
'float32': torch.FloatTensor,
'float16': torch.HalfTensor,
'int64': torch.LongTensor,
'int32': torch.IntTensor,



  
  
    
    
  
  


something like
def my_collate(batch):
    imgs,targets = zip(*batch)
    return torch.cat(imgs),torch.cat(targets)

and  use it in dataloader
dataloader = DataLoader(dataset,collate_fn=my_collate)