Skip to content

Commit

Permalink
[Fix] Fix memory overflow in the rotated box IoU calculation (#2134)
Browse files Browse the repository at this point in the history
* fix iou3d bug

* replace clamp_min with clamp
  • Loading branch information
JingweiZhang12 authored Dec 16, 2022
1 parent 4e28378 commit 68ef1d7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions mmdet3d/structures/bbox_3d/base_box3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 68ef1d7

Please sign in to comment.