如何通过 Pytorch 更改 Faster R-CNN 中 "maxdets" 的值?

How Can I change the value of "maxdets" in Faster R-CNN by Pytorch?

我正在 pytorch 上实现更快的 RCNN 网络。我已经按照下一个教程学习了。

https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html

有些图像中我有超过 100 个对象要分类。但是,在本教程中,我最多只能检测 100 个对象,因为参数 "maxdets" = 100.

有没有办法改变这个值以适应我的项目?

IoU metric: bbox
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.235
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.655
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.105
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.238
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.006
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.066
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.331
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.331
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000

如果只改变下一个参数,问题就解决了吗?

cocoeval.Params.setDetParams.maxDets = [1, 10, 100]

谢谢!

"There are images in which I have more than 100 objects to classify."

maxDets = 100 并不意味着它只会对 100 张图像进行分类,而是指 % AverageRecall given 100 detections per image

简而言之,maxDets 是指指标,而不是实际数量。分类图像的数量。

有关更多信息,请访问: http://cocodataset.org/#detection-eval

https://github.com/matterport/Mask_RCNN/issues/663

 # Limit to max_per_image detections **over all classes**
    if number_of_detections > self.detections_per_img > 0:
        cls_scores = result.get_field("scores")
        image_thresh, _ = torch.kthvalue(
            cls_scores.cpu(), number_of_detections - self.detections_per_img + 1
        )
        keep = cls_scores >= image_thresh.item()
        keep = torch.nonzero(keep).squeeze(1)
        result = result[keep]
    return result

根据这个代码片段,我发现它检查了号码。检测 所以 model.roi_heads.detections_per_img=300 对你的目的是正确的。 我还没有找到很多关于 maxdets 的合适文档,但我想上面的代码应该可以工作。

 # non-maximum suppression, independently done per class
   keep = box_ops.batched_nms(boxes, scores, labels, self.nms_thresh)
 # keep only topk scoring predictions
   keep = keep[:self.detections_per_img]

此代码片段表明我们可以仅过滤掉我们希望在模型中拥有的一些顶级检测。