import warnings
import torch
import mx_driving._C
class BoxesOverlapBev(torch.autograd.Function):
@staticmethod
def forward(ctx, boxes_a, boxes_b, inp_format, r_unit, clockwise, mode, aligned, margin):
format_dict = {
"xyxyr": 0,
"xywhr": 1,
"xyzxyzr": 2,
"xyzwhdr": 3
}
format_flag = 0
if inp_format in format_dict:
format_flag = format_dict[inp_format]
unit_dict = {
"radian": 0,
"degree": 1
}
unit_flag = 0
if r_unit in unit_dict:
unit_flag = unit_dict[r_unit]
mode_dict = {
"overlap": 0,
"iou": 1,
"iof": 2
}
mode_flag = 0
if mode in mode_dict:
mode_flag = mode_dict[mode]
res = mx_driving._C.npu_boxes_overlap_bev(boxes_a, boxes_b, format_flag, unit_flag, clockwise,
mode_flag, aligned, margin)
return res
def boxes_overlap_bev(boxes_a, boxes_b):
r_unit = "radian"
aligned = False
mode = "overlap"
margin = 1e-5
if boxes_a.shape[-1] == 5:
inp_format = "xyxyr"
clockwise = False
else:
inp_format = "xyzwhdr"
clockwise = True
return BoxesOverlapBev.apply(boxes_a, boxes_b, inp_format, r_unit, clockwise, mode, aligned, margin)
def npu_boxes_overlap_bev(boxes_a, boxes_b):
warnings.warn("`npu_boxes_overlap_bev` will be deprecated in future. Please use `boxes_overlap_bev` instead.", DeprecationWarning)
r_unit = "radian"
aligned = False
mode = "overlap"
margin = 1e-5
if boxes_a.shape[-1] == 5:
inp_format = "xyxyr"
clockwise = False
else:
inp_format = "xyzwhdr"
clockwise = True
return BoxesOverlapBev.apply(boxes_a, boxes_b, inp_format, r_unit, clockwise, mode, aligned, margin)
def boxes_iou_bev(boxes_a, boxes_b):
inp_format = "xyzwhdr"
r_unit = "radian"
clockwise = True
mode = "iou"
aligned = False
margin = 1e-5
return BoxesOverlapBev.apply(boxes_a, boxes_b, inp_format, r_unit, clockwise, mode, aligned, margin)