From 68ef1d79b814e4fd9b15a9f5b5fa1c4f4e8426da Mon Sep 17 00:00:00 2001 From: Jingwei Zhang Date: Fri, 16 Dec 2022 15:32:59 +0800 Subject: [PATCH] [Fix] Fix memory overflow in the rotated box IoU calculation (#2134) * fix iou3d bug * replace clamp_min with clamp --- mmdet3d/structures/bbox_3d/base_box3d.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mmdet3d/structures/bbox_3d/base_box3d.py b/mmdet3d/structures/bbox_3d/base_box3d.py index b3c25e998b..fba20ceb16 100644 --- a/mmdet3d/structures/bbox_3d/base_box3d.py +++ b/mmdet3d/structures/bbox_3d/base_box3d.py @@ -463,11 +463,17 @@ def overlaps(cls, boxes1, boxes2, mode='iou'): # height overlap overlaps_h = cls.height_overlaps(boxes1, boxes2) + # Restrict the min values of W and H to avoid memory overflow in + # ``box_iou_rotated``. + boxes1_bev, boxes2_bev = boxes1.bev, boxes2.bev + boxes1_bev[:, 2:4] = boxes1_bev[:, 2:4].clamp(min=1e-4) + boxes2_bev[:, 2:4] = boxes2.bev[:, 2:4].clamp(min=1e-4) + # bev overlap - iou2d = box_iou_rotated(boxes1.bev, boxes2.bev) - areas1 = (boxes1.bev[:, 2] * boxes1.bev[:, 3]).unsqueeze(1).expand( + iou2d = box_iou_rotated(boxes1_bev, boxes2_bev) + areas1 = (boxes1_bev[:, 2] * boxes1_bev[:, 3]).unsqueeze(1).expand( rows, cols) - areas2 = (boxes2.bev[:, 2] * boxes2.bev[:, 3]).unsqueeze(0).expand( + areas2 = (boxes2_bev[:, 2] * boxes2_bev[:, 3]).unsqueeze(0).expand( rows, cols) overlaps_bev = iou2d * (areas1 + areas2) / (1 + iou2d)