def boxlist_box_voting(top_boxlist, all_boxlist, thresh, scoring_method='ID', beta=1.0, score_field="scores"): if thresh <= 0: return top_boxlist mode = top_boxlist.mode top_boxes = top_boxlist.convert("xyxy").bbox.cpu() all_boxes = all_boxlist.convert("xyxy").bbox.cpu() top_score = top_boxlist.get_field(score_field).cpu() all_score = all_boxlist.get_field(score_field).cpu() top_dets = np.hstack((top_boxes, top_score[:, np.newaxis])).astype(np.float32, copy=False) all_dets = np.hstack((all_boxes, all_score[:, np.newaxis])).astype(np.float32, copy=False) dets = box_utils.box_voting(top_dets, all_dets, thresh, scoring_method, beta) boxlist = BoxList(torch.from_numpy(dets[:, :4]).cuda(), all_boxlist.size, mode="xyxy") boxlist.add_field("scores", torch.from_numpy(dets[:, -1]).cuda()) return boxlist.convert(mode)
def boxlist_soft_nms(boxlist, sigma=0.5, overlap_thresh=0.3, score_thresh=0.001, method='linear', score_field="scores"): """ Performs non-maximum suppression on a boxlist, with scores specified in a boxlist field via score_field. Arguments: boxlist(BoxList) nms_thresh (float) max_proposals (int): if > 0, then only the top max_proposals are kept after non-maximum suppression score_field (str) """ if overlap_thresh <= 0: return boxlist mode = boxlist.mode boxlist = boxlist.convert("xyxy") boxes = boxlist.bbox.cpu() score = boxlist.get_field(score_field).cpu() dets = np.hstack((boxes, score[:, np.newaxis])).astype(np.float32, copy=False) dets, _ = box_utils.soft_nms(dets, sigma, overlap_thresh, score_thresh, method) boxlist = BoxList(torch.from_numpy(dets[:, :4]).cuda(), boxlist.size, mode="xyxy") boxlist.add_field("scores", torch.from_numpy(dets[:, -1]).cuda()) return boxlist.convert(mode)