Skip to content

Commit 8966736

Browse files
committed
perf(util): 计算宽/高时加1
1 parent 1655474 commit 8966736

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

py/lib/utils/util.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
import numpy as np
1111
import torch
12+
import sys
13+
14+
15+
def error(msg):
16+
print(msg)
17+
sys.exit(0)
1218

1319

1420
def get_device():
@@ -30,10 +36,10 @@ def iou(pred_box, target_box):
3036
xB = np.minimum(pred_box[2], target_box[:, 2])
3137
yB = np.minimum(pred_box[3], target_box[:, 3])
3238
# 计算交集面积
33-
intersection = np.maximum(0.0, xB - xA) * np.maximum(0.0, yB - yA)
39+
intersection = np.maximum(0.0, xB - xA + 1) * np.maximum(0.0, yB - yA + 1)
3440
# 计算两个边界框面积
35-
boxAArea = (pred_box[2] - pred_box[0]) * (pred_box[3] - pred_box[1])
36-
boxBArea = (target_box[:, 2] - target_box[:, 0]) * (target_box[:, 3] - target_box[:, 1])
41+
boxAArea = (pred_box[2] - pred_box[0] + 1) * (pred_box[3] - pred_box[1] + 1)
42+
boxBArea = (target_box[:, 2] - target_box[:, 0] + 1) * (target_box[:, 3] - target_box[:, 1] + 1)
3743

3844
scores = intersection / (boxAArea + boxBArea - intersection)
3945
return scores
@@ -87,9 +93,9 @@ def bbox_corner_to_center(bboxs):
8793
tmp = np.zeros(bboxs.shape)
8894

8995
# w
90-
tmp[:, 2] = bboxs[:, 2] - bboxs[:, 0]
96+
tmp[:, 2] = bboxs[:, 2] - bboxs[:, 0] + 1
9197
# h
92-
tmp[:, 3] = bboxs[:, 3] - bboxs[:, 1]
98+
tmp[:, 3] = bboxs[:, 3] - bboxs[:, 1] + 1
9399
# x_center
94100
tmp[:, 0] = bboxs[:, 0] + tmp[:, 2] / 2
95101
# y_center

0 commit comments

Comments
 (0)