ChristianMarzahl / ObjectDetection

Some experiments with object detection in PyTorch
136 stars 43 forks source link

Tensor with no elements #5

Closed mking275 closed 4 years ago

mking275 commented 4 years ago

Im trying to run this notebook 'out of the box' and getting the following error:

RuntimeError Traceback (most recent call last)

in ----> 1 learn.lr_find() 2 learn.recorder.plot() ~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/train.py in lr_find(learn, start_lr, end_lr, num_it, stop_div, wd) 39 cb = LRFinder(learn, start_lr, end_lr, num_it, stop_div) 40 epochs = int(np.ceil(num_it/len(learn.data.train_dl))) ---> 41 learn.fit(epochs, start_lr, callbacks=[cb], wd=wd) 42 43 def to_fp16(learn:Learner, loss_scale:float=None, max_noskip:int=1000, dynamic:bool=True, clip:float=None, ~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/basic_train.py in fit(self, epochs, lr, wd, callbacks) 198 else: self.opt.lr,self.opt.wd = lr,wd 199 callbacks = [cb(self) for cb in self.callback_fns + listify(defaults.extra_callback_fns)] + listify(callbacks) --> 200 fit(epochs, self, metrics=self.metrics, callbacks=self.callbacks+callbacks) 201 202 def create_opt(self, lr:Floats, wd:Floats=0.)->None: ~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/basic_train.py in fit(epochs, learn, callbacks, metrics) 99 for xb,yb in progress_bar(learn.data.train_dl, parent=pbar): 100 xb, yb = cb_handler.on_batch_begin(xb, yb) --> 101 loss = loss_batch(learn.model, xb, yb, learn.loss_func, learn.opt, cb_handler) 102 if cb_handler.on_batch_end(loss): break 103 ~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/basic_train.py in loss_batch(model, xb, yb, loss_func, opt, cb_handler) 28 29 if not loss_func: return to_detach(out), to_detach(yb[0]) ---> 30 loss = loss_func(out, *yb) 31 32 if opt is not None: ~/anaconda3/envs/fastai/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs) 539 result = self._slow_forward(*input, **kwargs) 540 else: --> 541 result = self.forward(*input, **kwargs) 542 for hook in self._forward_hooks.values(): 543 hook_result = hook(self, input, result) ~/ObjectDetection/loss/RetinaNetFocalLoss.py in forward(self, output, bbox_tgts, clas_tgts) 53 focal_loss = torch.tensor(0, dtype=torch.float32).to(clas_preds.device) 54 for cp, bp, ct, bt in zip(clas_preds, bbox_preds, clas_tgts, bbox_tgts): ---> 55 bb, focal = self._one_loss(cp, bp, ct, bt) 56 57 bb_loss += bb ~/ObjectDetection/loss/RetinaNetFocalLoss.py in _one_loss(self, clas_pred, bbox_pred, clas_tgt, bbox_tgt) 28 29 def _one_loss(self, clas_pred, bbox_pred, clas_tgt, bbox_tgt): ---> 30 bbox_tgt, clas_tgt = self._unpad(bbox_tgt, clas_tgt) 31 matches = match_anchors(self.anchors, bbox_tgt) 32 bbox_mask = matches >= 0 ~/ObjectDetection/loss/RetinaNetFocalLoss.py in _unpad(self, bbox_tgt, clas_tgt) 15 16 def _unpad(self, bbox_tgt, clas_tgt): ---> 17 i = torch.min(torch.nonzero(clas_tgt - self.pad_idx)) 18 return tlbr2cthw(bbox_tgt[i:]), clas_tgt[i:] - 1 + self.pad_idx 19 RuntimeError: invalid argument 1: cannot perform reduction function min on tensor with no elements because the operation does not have an identity at /opt/conda/conda-bld/pytorch_1573049310284/work/aten/src/THC/generic/THCTensorMathReduce.cu:64
maubreville commented 4 years ago

This seems to be related to a change in pytorch.

maubreville commented 4 years ago

Fix worked (at least for me, admittedly in a different notebook but using the same model files)

mking275 commented 4 years ago

Worked for me too. Much thanks.