question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FastNMS on Ultralytics YOLOv3

See original GitHub issue

@dbolya we’ve had a request from @Zzh-tju to implement FastNMS in https://github.com/ultralytics/yolov3 per https://github.com/ultralytics/yolov3/issues/679. Can you point us to the location in your code where the function is? Can we use it for boxes rather than masks?

We currently use multi-class torchvision.ops.boxes.batched_nms() (middle row) as a compromise between speed and accuracy. We apply it once per image (all classes at once), and see an inference speed of 49ms/img (inference + NMS) at 608 image size, conf_thresh=0.001 on a Tesla T4, giving us about 42.0/62.0 mAP@0.5/0.5…0.95 on COCO2014. We do not do masks though, only boxes.

BTW, we also developed the merge nms method below, which is slower simply because it is implemented in python rather than C, but it may be possible to combine fast and merge together to get the best of both worlds.

NMS method Time
s/img
Time
mm:ss
mAP
@0.5:0.95
mAP
@0.5
'vision_batched', multi_cls=False 46ms 3:50 41.2 60.8
'vision_batched', multi_cls=True 49ms 4:03 41.9 61.8
'merge', multi_cls=True 120ms 9:58 42.3 62.0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:21 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
dbolyacommented, Mar 4, 2020

Looking at batched_nms, it looks like what we call cross_class NMS, but I’m not sure what that would make multi_cls=True.

Anyway, here’s our implementation of Fast NMS: https://github.com/dbolya/yolact/blob/092554ad707c2749631dfe545c8a953b2b3f4a68/layers/functions/detection.py#L137-L180

It works on boxes, so you can just ignore the mask stuff. The relevant inputs are boxes ([N, 4]) and scores ([N, num_classes]). The inputs and outputs should both be on the GPU (or whatever your fastest device is, and make sure nothing ever touches the CPU in this function), and we pass in all detections with > 0.05 confidence, but I don’t think passing everything in will hurt performance much since we take the top 200 anyway. Also, read the big comment about the second threshold.

Most of the code is setup and postprocessing, the core of the algorithm is actually just:

     iou = jaccard(boxes, boxes) 
     iou.triu_(diagonal=1) 
     iou_max, _ = iou.max(dim=1) 
  
     # Now just filter out the ones higher than the threshold 
     keep = (iou_max <= iou_threshold) 

which is what’s in the paper.

0reactions
glenn-jochercommented, Mar 26, 2020

@Gaondong see https://github.com/ultralytics/yolov3/issues/679#issuecomment-604164825

I used this code for Matrix (Soft) NMS:

            elif method == 'matrix':  # Matrix NMS from https://arxiv.org/abs/2003.10152
                iou = box_iou(boxes, boxes).triu_(diagonal=1)  # upper triangular iou matrix
                m = iou.max(0)[0].view(-1, 1)  # max values
                decay = torch.exp(-(iou ** 2 - m ** 2) / 0.5).min(0)[0]  # gauss with sigma=0.5
                scores *= decay
                i = torch.full((boxes.shape[0],), fill_value=1).bool()
Read more comments on GitHub >

github_iconTop Results From Across the Web

ultralytics/yolov3 - Docker Image
YOLOv3 is a family of object detection architectures and models pretrained on the COCO dataset, and represents Ultralytics open-source research into ...
Read more >
ultralytics/yolov3: v8 - Final Darknet Compatible Release
This is the final release of the darknet-compatible version of the https://github.com/ultralytics/yolov3 repository.
Read more >
Enhancing Geometric Factors in Model Learning and ... - DeepAI
Unfortunately, Fast NMS yields performance drop due to that many boxes ... v3 model in Pytorch, where the model YOLOv3-spp-Ultralytics-608 4 ...
Read more >
Enhancing Geometric Factors in Model Learning and ... - arXiv
BlendMask-RT), and object detection (e.g., YOLO v3, SSD and ... been developed for real-time inference, e.g., Fast NMS [20].
Read more >
(PDF) Enhancing Geometric Factors in Model Learning and ...
been developed for real-time inference, e.g., Fast NMS [20]. ... in Pytorch, where the model YOLOv3-spp-Ultralytics-6085.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found