Skip to content

Commit

Permalink
fix the bug of iou incorrect calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Melody-Zhou committed Jan 11, 2024
1 parent 6c9049c commit 5da538e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
15 changes: 8 additions & 7 deletions python/infer-pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ def preprocess_warpAffine(image, dst_width=640, dst_height=640):
return img_pre, IM

def iou(box1, box2):

def area_box(box):
return (box[2] - box[0]) * (box[3] - box[1])

left, top = max(box1[:2], box2[:2])
right, bottom = min(box1[2:4], box2[2:4])
union = max((right-left), 0) * max((bottom-top), 0)
cross = area_box(box1) + area_box(box2) - union

left = max(box1[0], box2[0])
top = max(box1[1], box2[1])
right = min(box1[2], box2[2])
bottom = min(box1[3], box2[3])
cross = max((right-left), 0) * max((bottom-top), 0)
union = area_box(box1) + area_box(box2) - cross
if cross == 0 or union == 0:
return 0
return union / cross
return cross / union

def NMS(boxes, iou_thres):

Expand Down
14 changes: 8 additions & 6 deletions python/infer-seg.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ def preprocess_warpAffine(image, dst_width=640, dst_height=640):
def iou(box1, box2):
def area_box(box):
return (box[2] - box[0]) * (box[3] - box[1])

left, top = max(box1[:2], box2[:2])
right, bottom = min(box1[2:4], box2[2:4])
union = max((right-left), 0) * max((bottom-top), 0)
cross = area_box(box1) + area_box(box2) - union

left = max(box1[0], box2[0])
top = max(box1[1], box2[1])
right = min(box1[2], box2[2])
bottom = min(box1[3], box2[3])
cross = max((right-left), 0) * max((bottom-top), 0)
union = area_box(box1) + area_box(box2) - cross
if cross == 0 or union == 0:
return 0
return union / cross
return cross / union

def NMS(boxes, iou_thres):

Expand Down
15 changes: 8 additions & 7 deletions python/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ def preprocess_warpAffine(image, dst_width=640, dst_height=640):
return img_pre, IM

def iou(box1, box2):

def area_box(box):
return (box[2] - box[0]) * (box[3] - box[1])

left, top = max(box1[:2], box2[:2])
right, bottom = min(box1[2:4], box2[2:4])
union = max((right - left), 0) * max((bottom - top), 0)
cross = area_box(box1) + area_box(box2) - union

left = max(box1[0], box2[0])
top = max(box1[1], box2[1])
right = min(box1[2], box2[2])
bottom = min(box1[3], box2[3])
cross = max((right-left), 0) * max((bottom-top), 0)
union = area_box(box1) + area_box(box2) - cross
if cross == 0 or union == 0:
return 0
return union / cross
return cross / union

def NMS(boxes, iou_thres):

Expand Down

0 comments on commit 5da538e

Please sign in to comment.