前言:
与Bounding Box有关的操作有很多,例如对边框列表进行非极大线性抑制、去除过小的边框、计算边框之间的Iou以及对两个边框列表进行合并等操作。在maskrcnn_benchmark中,这些操作都得以实现,其具体代码以及解释如下:
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import torch
from .bounding_box import BoxList
from maskrcnn_benchmark.layers import nms as _box_nms
def boxlist_nms(boxlist, nms_thresh, max_proposals=-1, score_field="scores"):
"""
Performs non-maximum suppression on a boxlist, with scores specified
in a boxlist field via score_field.在边框列表上进行非极大线性抑制
参数:
boxlist(BoxList):含有边框目标得分,原始图像大小,预测边框列表等信息的边框列表
nms_thresh (float):非极大线性抑制的阈值
max_proposals (int): if > 0, then only the top max_proposals are kept
after non-maximum suppression当大于0时,在非极大线性抑制后只保存前max_proposals个最大目标评分的的预测边框
score_field (str):保存目标得分列表的键值
"""
# 如果非极大线性抑制的阈值小于0,则返回所有边框列表
if nms_thresh <= 0:
return boxlist
# 得到预测边框的格式
m