From b5be2ef37acd73a97f88a1cf56c8e41b4792f06a Mon Sep 17 00:00:00 2001 From: Danila Rukhovich Date: Thu, 9 Jun 2022 17:11:19 +0300 Subject: [PATCH] fix depthinstance3dboxes.overlaps --- mmdet3d/core/bbox/structures/depth_box3d.py | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/mmdet3d/core/bbox/structures/depth_box3d.py b/mmdet3d/core/bbox/structures/depth_box3d.py index dd9278bfb4..77568fe8cd 100644 --- a/mmdet3d/core/bbox/structures/depth_box3d.py +++ b/mmdet3d/core/bbox/structures/depth_box3d.py @@ -268,3 +268,32 @@ def get_surface_line_center(self): line_center = center.repeat(1, 12, 1).reshape(-1, 3) + line_3d return surface_center, line_center + + @classmethod + def overlaps(cls, boxes1, boxes2, mode='iou'): + """Calculate 3D overlaps of two boxes. + + Note: + This function calculates the overlaps between ``boxes1`` and + ``boxes2``, ``boxes1`` and ``boxes2`` should be in the same type. + Args: + boxes1 (:obj:`BaseInstance3DBoxes`): Boxes 1 contain N boxes. + boxes2 (:obj:`BaseInstance3DBoxes`): Boxes 2 contain M boxes. + mode (str, optional): Mode of iou calculation. Defaults to 'iou'. + Returns: + torch.Tensor: Calculated 3D overlaps of the boxes. + """ + # We flip yaw angle here as mmcv.ops.box_iou_rotated accepts + # it in anti-clockwise direction. + if boxes1.with_yaw: + tensor1 = torch.cat( + (boxes1.tensor[:, :-1], -boxes1.tensor[:, -1:]), dim=-1) + boxes1 = DepthInstance3DBoxes( + tensor1, box_dim=boxes1.box_dim, with_yaw=boxes1.with_yaw) + if boxes2.with_yaw: + tensor2 = torch.cat( + (boxes2.tensor[:, :-1], -boxes2.tensor[:, -1:]), dim=-1) + boxes2 = DepthInstance3DBoxes( + tensor2, box_dim=boxes2.box_dim, with_yaw=boxes2.with_yaw) + + return super().overlaps(boxes1, boxes2)