来源:投稿 作者:LSC
编辑:学姐
- def iou(boxes, i, j):
- ax1, ay1, ax2, ay2 = boxes[i][1:5]
- bx1, by1, bx2, by2 = boxes[j][1:5]
- if ax1 >= bx2 or ay1 >= by2 or ax2 <= bx1 or ay2 <= by1:
- return 0
- cx1 = max(ax1, bx1)
- cx2 = min(ax2, bx2)
- cy1 = max(ay1, by1)
- cy2 = min(ay2, by2)
- u = (cy2 - cy1) * (cx2 - cx1)
- s = (ax2 - ax1) * (ay2 - ay1) + (bx2 - bx1) * (by2 - by1)
- return u / (s - u)
-
- def nms(boxes, the, iou_th=0.5):
- boxes1 = []
- for i in boxes:
- if i[-1] > the:
- boxes1.append(i)
- boxes1 = sorted(boxes1, lambda x:x[-1], reverse=True)
- for i in range(len(boxes1)):
- if boxes1[i][-1] == 0:
- continue
- for j in range(i + 1, len(boxes1)):
- if boxes1[j][-1] == 0:
- continue
- i = iou(boxes1, i, j)
- if i > iou_th:
- boxes1[j][-1] = 0
- res = []
- for i in boxes1:
- if i[-1] > 0:
- res.append(i)
- return res
我只写了大概,没有跑过
二面主要问项目,挖的比较深。
关注下方《学姐带你玩AI》🚀🚀🚀
算法工程师万能简历公式+200多个简历模板(中英文)
回复“简历”轻松获取!
码字不易,欢迎大家点赞评论收藏!