fastai / course-v3

The 3rd edition of course.fast.ai
https://course.fast.ai/
Apache License 2.0
4.91k stars 3.57k forks source link

RuntimeError: invalid argument 1: cannot perform reduction function min on tensor with no elements because the operation does not have an identity at /root/pytorch/aten/src/THH/generic/THHTensorMathReduce.hip:65 #502

Open rraminen opened 4 years ago

rraminen commented 4 years ago

In pascal.ipynb, the below error occurs

image

def _unpad(self, bbox_tgt, clas_tgt): ---> i = torch.min(torch.nonzero(clas_tgt-self.pad_idx)) return tlbr2cthw(bbox_tgt[i:]), clas_tgt[i:]-1+self.pad_idx

Reason: This occurs when clas_tgt is tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], device='cuda:0') . Then torch.nonzero(clas_tgt-self.pad_idx) becomes tensor([], device='cuda:0', size=(0, 1), dtype=torch.int64). As torch.nonzero(clas_tgt-self.pad_idx) is an empty tensor, applying torch.min() on an empty tensor throws this error.