hukkelas / DSFD-Pytorch-Inference

A High-Performance Pytorch Implementation of face detection models, including RetinaFace and DSFD
Apache License 2.0
218 stars 58 forks source link

Error while doing inference on video #2

Closed Math2code closed 5 years ago

Math2code commented 5 years ago

Hi all,

I encounter the following error while doing inference on video and it is likely to happen when I down-scale the frame. Do you know how should I fixed it ? ~\DSFD-Pytorch-Inference\dsfd\detect.py in detect_face(self, image, confidence_threshold, shrink) 41 42 with torch.no_grad(): ---> 43 y = self.net(x, confidence_threshold, self.nms_iou_threshold) 44 45 detections = y.data.cpu().numpy()

~\Anaconda3\envs\py36\lib\site-packages\torch\nn\modules\module.py in call(self, *input, kwargs) 545 result = self._slow_forward(*input, *kwargs) 546 else: --> 547 result = self.forward(input, kwargs) 548 for hook in self._forward_hooks.values(): 549 hook_result = hook(self, input, result)

\DSFD-Pytorch-Inference\dsfd\face_ssd.py in forward(self, x, confidence_threshold, nms_threshold) 191 self.priors, 192 confidence_threshold, --> 193 nms_threshold 194 ) 195 return output

~\DSFD-Pytorch-Inference\dsfd\utils.py in forward(self, loc_data, conf_data, prior_data, confidence_threshold, nms_threshold) 65 if conf_scores.dim() == 0: 66 final_ouput.append(torch.empty(0, 5)) ---> 67 keep_idx = nms(decoded_boxes, conf_scores, nms_threshold) 68 69 scores = conf_scores[keep_idx].view(1, -1, 1)

~\Anaconda3\envs\py36\lib\site-packages\torchvision\ops\boxes.py in nms(boxes, scores, iou_threshold) 31 """ 32 _C = _lazy_import() ---> 33 return _C.nms(boxes, scores, iou_threshold) 34 35

RuntimeError: too many indices for tensor of dimension 0 (got 1) (index at ..\aten\src\ATen\native\Indexing.cpp:235) (no backtrace available)

Math2code commented 5 years ago

I had an ad-hoc solution as follow: at /dsfd/utils.py indices = (conf_scores >= confidence_threshold).nonzero().squeeze() decoded_boxes = decoded_boxes[indices] conf_scores = conf_scores[indices]

        if decoded_boxes.dim() == 1: 
            decoded_boxes =  torch.empty(0,4).cuda()
            conf_scores = torch.empty(0, 5).cuda()
hukkelas commented 5 years ago

Hey, thanks for noticing this bug. I've experienced this with the DeepPrivacy github, but forgot to submit a bug fix in this repo. This commit should fix the issue :)

The issue is that when there is no bounding box predictions with a higher confidence than the threshold, the NMS code spits out that error.