Skip to content

Commit 370700b

Browse files
committed
update box_iou_rotated
1 parent 6c0ff7e commit 370700b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Diff for: detectron2/layers/csrc/box_iou_rotated/box_iou_rotated_utils.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ HOST_DEVICE_INLINE int get_intersection_points(
8686
vec2[i] = pts2[(i + 1) % 4] - pts2[i];
8787
}
8888

89+
// When computing the intersection area, it doesn't hurt if we have
90+
// more (duplicated/approximate) intersections/vertices than needed,
91+
// while it can cause drastic difference if we miss an intersection/vertex.
92+
// Therefore, we add an epsilon to relax the comparisons between
93+
// the float point numbers that decide the intersection points.
94+
double EPS = 1e-5;
95+
8996
// Line test - test all line combos for intersection
9097
int num = 0; // number of intersections
9198
for (int i = 0; i < 4; i++) {
@@ -103,7 +110,7 @@ HOST_DEVICE_INLINE int get_intersection_points(
103110
T t1 = cross_2d<T>(vec2[j], vec12) / det;
104111
T t2 = cross_2d<T>(vec1[i], vec12) / det;
105112

106-
if (t1 >= 0.0f && t1 <= 1.0f && t2 >= 0.0f && t2 <= 1.0f) {
113+
if (t1 > -EPS && t1 < 1.0f + EPS && t2 > -EPS && t2 < 1.0f + EPS) {
107114
intersections[num++] = pts1[i] + vec1[i] * t1;
108115
}
109116
}
@@ -125,8 +132,8 @@ HOST_DEVICE_INLINE int get_intersection_points(
125132
auto APdotAB = dot_2d<T>(AP, AB);
126133
auto APdotAD = -dot_2d<T>(AP, DA);
127134

128-
if ((APdotAB >= 0) && (APdotAD >= 0) && (APdotAB <= ABdotAB) &&
129-
(APdotAD <= ADdotAD)) {
135+
if ((APdotAB > -EPS) && (APdotAD > -EPS) && (APdotAB < ABdotAB + EPS) &&
136+
(APdotAD < ADdotAD + EPS)) {
130137
intersections[num++] = pts1[i];
131138
}
132139
}
@@ -144,8 +151,8 @@ HOST_DEVICE_INLINE int get_intersection_points(
144151
auto APdotAB = dot_2d<T>(AP, AB);
145152
auto APdotAD = -dot_2d<T>(AP, DA);
146153

147-
if ((APdotAB >= 0) && (APdotAD >= 0) && (APdotAB <= ABdotAB) &&
148-
(APdotAD <= ADdotAD)) {
154+
if ((APdotAB > -EPS) && (APdotAD > -EPS) && (APdotAB < ABdotAB + EPS) &&
155+
(APdotAD < ADdotAD + EPS)) {
149156
intersections[num++] = pts2[i];
150157
}
151158
}

Diff for: detectron2/modeling/poolers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def __init__(
168168
assert (
169169
len(scales) == self.max_level - self.min_level + 1
170170
), "[ROIPooler] Sizes of input featuremaps do not form a pyramid!"
171-
assert 0 < self.min_level and self.min_level <= self.max_level
171+
assert 0 <= self.min_level and self.min_level <= self.max_level
172172
if len(scales) > 1:
173173
# When there is only one feature map, canonical_level is redundant and we should not
174174
# require it to be a sensible value. Therefore we skip this assertion

0 commit comments

Comments
 (0)