Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
e254e7c6
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e254e7c6
编写于
2月 16, 2022
作者:
T
TTerror
提交者:
GitHub
2月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize prior_box for kunlun, *test=kunlun (#39477)
上级
f138371c
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
182 addition
and
177 deletion
+182
-177
paddle/fluid/operators/detection/prior_box_op_xpu.cc
paddle/fluid/operators/detection/prior_box_op_xpu.cc
+7
-10
python/paddle/fluid/tests/unittests/xpu/test_prior_box_op_xpu.py
...paddle/fluid/tests/unittests/xpu/test_prior_box_op_xpu.py
+175
-167
未找到文件。
paddle/fluid/operators/detection/prior_box_op_xpu.cc
浏览文件 @
e254e7c6
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#ifdef PADDLE_WITH_XPU
#include "paddle/fluid/operators/detection/prior_box_op.h"
#include "paddle/fluid/platform/device/device_wrapper.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -81,21 +82,17 @@ class PriorBoxOpXPUKernel : public framework::OpKernel<T> {
dev_ctx
.
x_context
(),
boxes_data
,
aspect_ratios_param
,
min_sizes_param
,
max_sizes_param
,
feature_height
,
feature_width
,
img_height
,
img_width
,
offset
,
step_height
,
step_width
,
clip
,
min_max_aspect_ratios_order
);
PADDLE_ENFORCE_EQ
(
ret
,
XPU_SUCCESS
,
platform
::
errors
::
External
(
"XPU gen_prior_box kernel return wrong value[%d %s]"
,
ret
,
XPUAPIErrorMsg
[
ret
]));
PADDLE_ENFORCE_XDNN_SUCCESS
(
ret
,
"gen_prior_box"
);
int
box_num
=
feature_height
*
feature_width
*
num_priors
;
int
vlen
=
variances
.
size
();
std
::
vector
<
K
>
var_cpu
(
vlen
*
box_num
);
for
(
int
i
=
0
;
i
<
box_num
;
++
i
)
{
ret
=
xpu_memcpy
(
vars_data
+
i
*
vlen
,
variances
.
data
(),
vlen
*
sizeof
(
K
),
XPUMemcpyKind
::
XPU_HOST_TO_DEVICE
);
PADDLE_ENFORCE_EQ
(
ret
,
XPU_SUCCESS
,
platform
::
errors
::
External
(
"XPU xpu_memcpy return wrong "
"value[%d %s] in prior_box."
,
ret
,
XPUAPIErrorMsg
[
ret
]));
std
::
copy
(
variances
.
begin
(),
variances
.
end
(),
var_cpu
.
begin
()
+
i
*
vlen
);
}
ret
=
xpu_memcpy
(
vars_data
,
var_cpu
.
data
(),
var_cpu
.
size
()
*
sizeof
(
K
),
XPUMemcpyKind
::
XPU_HOST_TO_DEVICE
);
PADDLE_ENFORCE_XPU_SUCCESS
(
ret
);
}
};
...
...
python/paddle/fluid/tests/unittests/xpu/test_prior_box_op_xpu.py
浏览文件 @
e254e7c6
...
...
@@ -14,19 +14,32 @@
from
__future__
import
print_function
import
unittest
import
math
import
numpy
as
np
import
sys
import
unittest
sys
.
path
.
append
(
".."
)
import
math
import
paddle
from
op_test
import
OpTest
from
op_test_xpu
import
XPUOpTest
from
xpu.get_test_cover_info
import
create_test_class
,
get_xpu_op_support_types
,
XPUOpTestWrapper
paddle
.
enable_static
()
class
TestPriorBoxOp
(
XPUOpTest
):
class
XPUTestPriorBoxOp
(
XPUOpTestWrapper
):
def
__init__
(
self
):
self
.
op_name
=
'prior_box'
self
.
use_dynamic_create_class
=
False
class
TestPriorBoxOp
(
XPUOpTest
):
def
setUp
(
self
):
self
.
op_type
=
"prior_box"
self
.
use_xpu
=
True
self
.
dtype
=
self
.
in_type
self
.
set_data
()
def
set_data
(
self
):
self
.
init_test_params
()
self
.
init_test_input
()
...
...
@@ -53,14 +66,6 @@ class TestPriorBoxOp(XPUOpTest):
place
=
paddle
.
XPUPlace
(
0
)
self
.
check_output_with_place
(
place
)
def
test_check_grad
(
self
):
pass
def
setUp
(
self
):
self
.
op_type
=
"prior_box"
self
.
use_xpu
=
True
self
.
set_data
()
def
set_max_sizes
(
self
):
max_sizes
=
[
5
,
10
]
self
.
max_sizes
=
np
.
array
(
max_sizes
).
astype
(
'float32'
).
tolist
()
...
...
@@ -103,16 +108,16 @@ class TestPriorBoxOp(XPUOpTest):
def
init_test_input
(
self
):
self
.
image
=
np
.
random
.
random
(
(
self
.
batch_size
,
self
.
image_channels
,
self
.
image_w
,
self
.
image_h
)).
astype
(
'float32'
)
self
.
image_h
)).
astype
(
self
.
dtype
)
self
.
input
=
np
.
random
.
random
(
(
self
.
batch_size
,
self
.
input_channels
,
self
.
layer_w
,
self
.
layer_h
)).
astype
(
'float32'
)
self
.
layer_h
)).
astype
(
self
.
dtype
)
def
init_test_output
(
self
):
out_dim
=
(
self
.
layer_h
,
self
.
layer_w
,
self
.
num_priors
,
4
)
out_boxes
=
np
.
zeros
(
out_dim
).
astype
(
'float32'
)
out_var
=
np
.
zeros
(
out_dim
).
astype
(
'float32'
)
out_boxes
=
np
.
zeros
(
out_dim
).
astype
(
self
.
dtype
)
out_var
=
np
.
zeros
(
out_dim
).
astype
(
self
.
dtype
)
idx
=
0
for
h
in
range
(
self
.
layer_h
):
...
...
@@ -147,10 +152,11 @@ class TestPriorBoxOp(XPUOpTest):
idx
+=
1
else
:
c_w
=
c_h
=
min_size
/
2.
out_boxes
[
h
,
w
,
idx
,
:]
=
[(
c_x
-
c_w
)
/
self
.
image_w
,
(
c_y
-
c_h
)
/
self
.
image_h
,
(
c_x
+
c_w
)
/
self
.
image_w
,
(
c_y
+
c_h
)
/
self
.
image_h
]
out_boxes
[
h
,
w
,
idx
,
:]
=
[
(
c_x
-
c_w
)
/
self
.
image_w
,
(
c_y
-
c_h
)
/
self
.
image_h
,
(
c_x
+
c_w
)
/
self
.
image_w
,
(
c_y
+
c_h
)
/
self
.
image_h
]
idx
+=
1
if
len
(
self
.
max_sizes
)
>
0
:
max_size
=
self
.
max_sizes
[
s
]
...
...
@@ -183,19 +189,21 @@ class TestPriorBoxOp(XPUOpTest):
# set the variance.
out_var
=
np
.
tile
(
self
.
variances
,
(
self
.
layer_h
,
self
.
layer_w
,
self
.
num_priors
,
1
))
self
.
out_boxes
=
out_boxes
.
astype
(
'float32'
)
self
.
out_var
=
out_var
.
astype
(
'float32'
)
self
.
out_boxes
=
out_boxes
.
astype
(
self
.
dtype
)
self
.
out_var
=
out_var
.
astype
(
self
.
dtype
)
class
TestPriorBoxOpWithoutMaxSize
(
TestPriorBoxOp
):
class
TestPriorBoxOpWithoutMaxSize
(
TestPriorBoxOp
):
def
set_max_sizes
(
self
):
self
.
max_sizes
=
[]
class
TestPriorBoxOpWithSpecifiedOutOrder
(
TestPriorBoxOp
):
class
TestPriorBoxOpWithSpecifiedOutOrder
(
TestPriorBoxOp
):
def
set_min_max_aspect_ratios_order
(
self
):
self
.
min_max_aspect_ratios_order
=
True
support_types
=
get_xpu_op_support_types
(
'prior_box'
)
for
stype
in
support_types
:
create_test_class
(
globals
(),
XPUTestPriorBoxOp
,
stype
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录