From 2ed5eb51ee96dffe536b2d4dcfee784fc20356df Mon Sep 17 00:00:00 2001 From: zhuweichen Date: Fri, 21 Jun 2024 15:44:08 +0800 Subject: [PATCH] adapt box_iou_rotaed to boxes_overlap_bev Update box_iou_rotated_npu.cpp --- mmcv/ops/box_iou_rotated.py | 9 +++++---- mmcv/ops/csrc/pytorch/npu/box_iou_rotated_npu.cpp | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mmcv/ops/box_iou_rotated.py b/mmcv/ops/box_iou_rotated.py index a811531d42..0f8a8e298b 100644 --- a/mmcv/ops/box_iou_rotated.py +++ b/mmcv/ops/box_iou_rotated.py @@ -143,10 +143,11 @@ def box_iou_rotated(bboxes1: torch.Tensor, bboxes1 = bboxes1 * flip_mat bboxes2 = bboxes2 * flip_mat if bboxes1.device.type == 'npu': - scale_mat = bboxes1.new_ones(bboxes1.shape[-1]) - scale_mat[-1] = 1.0 / 0.01745329252 - bboxes1 = bboxes1 * scale_mat - bboxes2 = bboxes2 * scale_mat + if (mode_flag == 1 or aligned or not clockwise): + scale_mat = bboxes1.new_ones(bboxes1.shape[-1]) + scale_mat[-1] = 1.0 / 0.01745329252 + bboxes1 = bboxes1 * scale_mat + bboxes2 = bboxes2 * scale_mat bboxes1 = bboxes1.contiguous() bboxes2 = bboxes2.contiguous() ext_module.box_iou_rotated( diff --git a/mmcv/ops/csrc/pytorch/npu/box_iou_rotated_npu.cpp b/mmcv/ops/csrc/pytorch/npu/box_iou_rotated_npu.cpp index c6e6b66478..14df358080 100644 --- a/mmcv/ops/csrc/pytorch/npu/box_iou_rotated_npu.cpp +++ b/mmcv/ops/csrc/pytorch/npu/box_iou_rotated_npu.cpp @@ -8,6 +8,14 @@ void box_iou_rotated_impl(const Tensor boxes1, const Tensor boxes2, Tensor ious, void box_iou_rotated_npu(const Tensor boxes1, const Tensor boxes2, Tensor ious, const int mode_flag, const bool aligned) { + if (mode_flag == 0 && aligned == false) { + auto trans = false; + auto is_clockwise = false; + auto need_iou = true; + EXEC_NPU_CMD(aclnnBoxesOverlapBev, boxes1, boxes2, trans, is_clockwise, + need_iou, ious); + return; + } at::Tensor boxes = at::ones_like(boxes1); at::Tensor query_boxes = at::ones_like(boxes2); boxes = boxes1.transpose(0, 1).unsqueeze(0);