之前在研究目标检测推理时后处理时,只了解了会进行预测框之间的非极大值抑制(nms),但在仔细研究了YOLOV8的nms源码后,发现它的做法并非传统的nms,而是会进行类别偏移处理。简单地说,就是如果我们的数据集存在的类别num_classes > 1时,在推理的过程中,并不会直接对重叠程度较高的预测框直接进行处理,而是如果预测框之间属于不同的类别,我们不能简单地进行过滤,因为很有可能两个不同类别的目标临近存在,直接过滤将导致漏检。
那么YOLOV8是怎么做的呢,我们直接看代码:
def non_max_suppression(
prediction,
conf_thres=0.25,
iou_thres=0.45,
classes=None,
agnostic=False,
multi_label=False,
labels=(),
max_det=300,
nc=0, # number of classes (optional)
max_time_img=0.05,
max_nms=30000,
max_wh=7680,
in_place=True,
rotated=False,
):
"""
Perform non-maximum suppression (NMS) on a set of boxes, with support for masks and multiple labels per box.
Args:
prediction (torch.Tensor): A tensor of shape (batch_size, num_classes + 4 + num_masks, num_boxes)
containing the predicted boxes, classes, and masks. The tensor should be in the format
output by a model, such as YOLO.
conf_thres (float): The confidence threshold below which boxes will be filtered out.
Valid values are between 0.0 and 1.0.
iou_thres (float): The IoU threshold below which boxes will be filtered out during NMS.
Valid values are between 0.0 and 1.0.
classes (List[int]): A list of class indices to consider. If None, all classes will be consider

最低0.47元/天 解锁文章
7536

被折叠的 条评论
为什么被折叠?



