Skip to content
GitLab
探索
登录
主导航
搜索或转到…
项目
P
Paddle
管理
动态
成员
标记
计划
议题
0
议题看板
里程碑
迭代
Wiki
代码
合并请求
0
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
产物
部署
发布
软件包库
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
Contributor analytics
CI/CD 分析
仓库分析
代码评审分析
议题分析
模型实验
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
快捷键
?
支持
扫描加入微信群:
1. 获取企业级DevOps解决方案支持
2. 免费或折扣极狐GitLab 官方培训认证
代码片段
群组
项目
HPCSource
Paddle
提交
c816121d
提交
c816121d
编辑于
6年前
作者:
baiyf
提交者:
qingqing01
6年前
浏览文件
操作
下载
补丁
差异文件
optimized iou_similarity_op (#10231)
上级
6d934560
分支
分支 包含提交
标签
v0.12.0
标签 包含提交
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
paddle/fluid/operators/iou_similarity_op.h
+13
-11
13 个添加, 11 个删除
paddle/fluid/operators/iou_similarity_op.h
python/paddle/fluid/tests/unittests/test_iou_similarity_op.py
+22
-8
22 个添加, 8 个删除
...on/paddle/fluid/tests/unittests/test_iou_similarity_op.py
有
35 个添加
和
19 个删除
paddle/fluid/operators/iou_similarity_op.h
+
13
−
11
浏览文件 @
c816121d
...
...
@@ -41,22 +41,24 @@ struct IOUSimilarityFunctor {
IOUSimilarityFunctor
(
const
T
*
x
,
const
T
*
y
,
T
*
z
,
int
cols
)
:
x_
(
x
),
y_
(
y
),
z_
(
z
),
cols_
(
static_cast
<
size_t
>
(
cols
))
{}
inline
HOSTDEVICE
void
operator
()(
size_t
row_id
)
const
{
inline
HOSTDEVICE
void
operator
()(
size_t
tid
)
const
{
size_t
row_id
=
tid
/
cols_
;
size_t
col_id
=
tid
%
cols_
;
T
x_min1
=
x_
[
row_id
*
4
];
T
y_min1
=
x_
[
row_id
*
4
+
1
];
T
x_max1
=
x_
[
row_id
*
4
+
2
];
T
y_max1
=
x_
[
row_id
*
4
+
3
];
for
(
size_t
i
=
0
;
i
<
cols_
;
++
i
)
{
T
x_min2
=
y_
[
i
*
4
];
T
y_min2
=
y_
[
i
*
4
+
1
];
T
x_max2
=
y_
[
i
*
4
+
2
];
T
y_max2
=
y_
[
i
*
4
+
3
];
T
sim
=
IOUSimilarity
(
x_min1
,
y_min1
,
x_max1
,
y_max1
,
x_min2
,
y_min2
,
x_max2
,
y_max2
);
T
x_min2
=
y_
[
col_id
*
4
];
T
y_min2
=
y_
[
col_id
*
4
+
1
];
T
x_max2
=
y_
[
col_id
*
4
+
2
];
T
y_max2
=
y_
[
col_id
*
4
+
3
];
T
sim
=
IOUSimilarity
(
x_min1
,
y_min1
,
x_max1
,
y_max1
,
x_min2
,
y_min2
,
x_max2
,
y_max2
);
z_
[
row_id
*
cols_
+
i
]
=
sim
;
}
z_
[
row_id
*
cols_
+
col_id
]
=
sim
;
}
const
T
*
x_
;
const
T
*
y_
;
...
...
@@ -81,7 +83,7 @@ class IOUSimilarityKernel : public framework::OpKernel<T> {
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
()),
y_n
);
platform
::
ForRange
<
DeviceContext
>
for_range
(
static_cast
<
const
DeviceContext
&>
(
ctx
.
device_context
()),
x_n
);
static_cast
<
const
DeviceContext
&>
(
ctx
.
device_context
()),
x_n
*
y_n
);
for_range
(
functor
);
}
};
// namespace operators
...
...
This diff is collapsed.
Click to expand it.
python/paddle/fluid/tests/unittests/test_iou_similarity_op.py
+
22
−
8
浏览文件 @
c816121d
...
...
@@ -14,6 +14,7 @@
import
unittest
import
numpy
as
np
import
numpy.random
as
random
import
sys
import
math
from
op_test
import
OpTest
...
...
@@ -25,14 +26,27 @@ class TestIOUSimilarityOp(OpTest):
def
setUp
(
self
):
self
.
op_type
=
"
iou_similarity
"
self
.
boxes1
=
np
.
array
(
[[
4.0
,
3.0
,
7.0
,
5.0
],
[
5.0
,
6.0
,
10.0
,
7.0
]]).
astype
(
'
float32
'
)
self
.
boxes2
=
np
.
array
([[
3.0
,
4.0
,
6.0
,
8.0
],
[
14.0
,
14.0
,
15.0
,
15.0
],
[
0.0
,
0.0
,
20.0
,
20.0
]]).
astype
(
'
float32
'
)
self
.
output
=
np
.
array
(
[[
2.0
/
16.0
,
0
,
6.0
/
400.0
],
[
1.0
/
16.0
,
0.0
,
5.0
/
400.0
]]).
astype
(
'
float32
'
)
self
.
boxes1
=
random
.
rand
(
2
,
4
).
astype
(
'
float32
'
)
self
.
boxes2
=
random
.
rand
(
3
,
4
).
astype
(
'
float32
'
)
self
.
output
=
random
.
rand
(
2
,
3
).
astype
(
'
float32
'
)
for
row
in
range
(
self
.
boxes1
.
shape
[
0
]):
for
col
in
range
(
self
.
boxes2
.
shape
[
0
]):
xmin1
,
ymin1
,
xmax1
,
ymax1
=
self
.
boxes1
[
row
]
xmin2
,
ymin2
,
xmax2
,
ymax2
=
self
.
boxes2
[
col
]
area1
=
(
ymax1
-
ymin1
)
*
(
xmax1
-
xmin1
)
area2
=
(
ymax2
-
ymin2
)
*
(
xmax2
-
xmin2
)
inter_xmax
=
min
(
xmax1
,
xmax2
)
inter_ymax
=
min
(
ymax1
,
ymax2
)
inter_xmin
=
max
(
xmin1
,
xmin2
)
inter_ymin
=
max
(
ymin1
,
ymin2
)
inter_height
=
inter_ymax
-
inter_ymin
inter_width
=
inter_xmax
-
inter_xmin
inter_height
=
max
(
inter_height
,
0
)
inter_width
=
max
(
inter_width
,
0
)
inter_area
=
inter_width
*
inter_height
union_area
=
area1
+
area2
-
inter_area
sim_score
=
inter_area
/
union_area
self
.
output
[
row
,
col
]
=
sim_score
self
.
inputs
=
{
'
X
'
:
self
.
boxes1
,
'
Y
'
:
self
.
boxes2
}
self
.
outputs
=
{
'
Out
'
:
self
.
output
}
...
...
This diff is collapsed.
Click to expand it.
预览
0%
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录