Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
last_winter
yolov4-pytorch
提交
f718a7c2
Y
yolov4-pytorch
项目概览
last_winter
/
yolov4-pytorch
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yolov4-pytorch
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
f718a7c2
编写于
1月 14, 2021
作者:
B
Bubbliiiing
提交者:
GitHub
1月 14, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Delete ciou_test.py
上级
62928870
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
59 deletion
+0
-59
ciou_test.py
ciou_test.py
+0
-59
未找到文件。
ciou_test.py
已删除
100644 → 0
浏览文件 @
62928870
import
math
import
numpy
as
np
import
torch
def
box_ciou
(
b1
,
b2
):
"""
输入为:
----------
b1: tensor, shape=(batch, feat_w, feat_h, anchor_num, 4), xywh
b2: tensor, shape=(batch, feat_w, feat_h, anchor_num, 4), xywh
返回为:
-------
ciou: tensor, shape=(batch, feat_w, feat_h, anchor_num, 1)
"""
# 求出预测框左上角右下角
b1_xy
=
b1
[...,
:
2
]
b1_wh
=
b1
[...,
2
:
4
]
b1_wh_half
=
b1_wh
/
2.
b1_mins
=
b1_xy
-
b1_wh_half
b1_maxes
=
b1_xy
+
b1_wh_half
# 求出真实框左上角右下角
b2_xy
=
b2
[...,
:
2
]
b2_wh
=
b2
[...,
2
:
4
]
b2_wh_half
=
b2_wh
/
2.
b2_mins
=
b2_xy
-
b2_wh_half
b2_maxes
=
b2_xy
+
b2_wh_half
# 求真实框和预测框所有的iou
intersect_mins
=
torch
.
max
(
b1_mins
,
b2_mins
)
intersect_maxes
=
torch
.
min
(
b1_maxes
,
b2_maxes
)
intersect_wh
=
torch
.
max
(
intersect_maxes
-
intersect_mins
,
torch
.
zeros_like
(
intersect_maxes
))
intersect_area
=
intersect_wh
[...,
0
]
*
intersect_wh
[...,
1
]
b1_area
=
b1_wh
[...,
0
]
*
b1_wh
[...,
1
]
b2_area
=
b2_wh
[...,
0
]
*
b2_wh
[...,
1
]
union_area
=
b1_area
+
b2_area
-
intersect_area
iou
=
intersect_area
/
(
union_area
+
1e-7
)
# 计算中心的差距
center_distance
=
torch
.
sum
(
torch
.
pow
((
b1_xy
-
b2_xy
),
2
),
axis
=-
1
)
# 找到包裹两个框的最小框的左上角和右下角
enclose_mins
=
torch
.
min
(
b1_mins
,
b2_mins
)
enclose_maxes
=
torch
.
max
(
b1_maxes
,
b2_maxes
)
enclose_wh
=
torch
.
max
(
enclose_maxes
-
enclose_mins
,
torch
.
zeros_like
(
intersect_maxes
))
# 计算对角线距离
enclose_diagonal
=
torch
.
sum
(
torch
.
pow
(
enclose_wh
,
2
),
axis
=-
1
)
ciou
=
iou
-
1.0
*
(
center_distance
)
/
(
enclose_diagonal
+
1e-7
)
v
=
(
4
/
(
math
.
pi
**
2
))
*
torch
.
pow
((
torch
.
atan
(
b1_wh
[...,
0
]
/
b1_wh
[...,
1
])
-
torch
.
atan
(
b2_wh
[...,
0
]
/
b2_wh
[...,
1
])),
2
)
alpha
=
v
/
(
1.0
-
iou
+
v
)
ciou
=
ciou
-
alpha
*
v
return
ciou
box1
=
torch
.
from_numpy
(
np
.
array
([[
25
,
25
,
40
,
40
]])).
type
(
torch
.
FloatTensor
)
box2
=
torch
.
from_numpy
(
np
.
array
([[
25
,
25
,
30
,
40
]])).
type
(
torch
.
FloatTensor
)
print
(
box_ciou
(
box1
,
box2
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录