Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
1d3754aa
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1d3754aa
编写于
9月 21, 2020
作者:
S
Santa An
提交者:
GitHub
9月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[LITE][BM] support multiclass_nms2 and fix some issues, test=develop (#4379)
上级
26c0ecc8
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
72 addition
and
15 deletion
+72
-15
lite/kernels/bm/bridges/box_coder_op.cc
lite/kernels/bm/bridges/box_coder_op.cc
+7
-1
lite/kernels/bm/bridges/cast_op.cc
lite/kernels/bm/bridges/cast_op.cc
+2
-1
lite/kernels/bm/bridges/elementwise_ops.cc
lite/kernels/bm/bridges/elementwise_ops.cc
+23
-4
lite/kernels/bm/bridges/multiclass_nms_op.cc
lite/kernels/bm/bridges/multiclass_nms_op.cc
+34
-4
lite/kernels/bm/bridges/paddle_use_bridges.h
lite/kernels/bm/bridges/paddle_use_bridges.h
+1
-0
lite/kernels/bm/bridges/yolo_box_op.cc
lite/kernels/bm/bridges/yolo_box_op.cc
+5
-5
未找到文件。
lite/kernels/bm/bridges/box_coder_op.cc
浏览文件 @
1d3754aa
...
...
@@ -73,10 +73,16 @@ int BoxCoderConverter(void* ctx, OpLite* op, KernelBase* kernel) {
if
(
op_info
->
HasAttr
(
"variance"
))
{
variance
=
op_info
->
GetAttr
<
std
::
vector
<
float
>>
(
"variance"
);
}
int
variance_len
=
variance
.
size
();
user_cpu_param_t
bm_param
;
bm_param
.
op_type
=
USER_PADDLE_BOX_CODER
;
bm_param
.
u
.
box_coder_param
.
axis
=
axis
;
bm_param
.
u
.
box_coder_param
.
variance
=
&
variance
[
0
];
CHECK_LE
(
variance_len
,
2000
);
memset
(
bm_param
.
u
.
box_coder_param
.
variance
,
0
,
2000
*
sizeof
(
float
));
memcpy
(
bm_param
.
u
.
box_coder_param
.
variance
,
&
variance
[
0
],
variance_len
*
sizeof
(
float
));
bm_param
.
u
.
box_coder_param
.
variance_len
=
variance_len
;
bm_param
.
u
.
box_coder_param
.
code_type
=
(
code_type
==
"encode_center_size"
)
?
0
:
1
;
bm_param
.
u
.
box_coder_param
.
normalized
=
box_normalized
;
...
...
lite/kernels/bm/bridges/cast_op.cc
浏览文件 @
1d3754aa
...
...
@@ -32,7 +32,8 @@ bool CvtDtype(int dtype, int* ptype) {
*
ptype
=
DTYPE_INT16
;
break
;
case
2
:
*
ptype
=
DTYPE_FP32
;
case
3
:
*
ptype
=
DTYPE_INT32
;
break
;
case
5
:
*
ptype
=
DTYPE_FP32
;
...
...
lite/kernels/bm/bridges/elementwise_ops.cc
浏览文件 @
1d3754aa
...
...
@@ -127,7 +127,7 @@ int ElementwiseConverter(void* ctx, OpLite* op, KernelBase* kernel) {
const
float
*
y_data
=
const_cast
<
const
float
*>
(
y
->
mutable_data
<
float
>
());
const
float
*
x_data
=
const_cast
<
const
float
*>
(
x
->
mutable_data
<
float
>
());
auto
unique_op_name
=
lite
::
subgraph
::
bm
::
UniqueName
(
"expand_ndims"
);
std
::
vector
<
int32_t
>
i_expand_shape_data
(
3
)
;
std
::
vector
<
int32_t
>
i_expand_shape_data
;
if
(
x_is_const
&&
y_is_const
)
{
float
*
cpu_data
=
compute_elementwise_both_const
(
op
);
bm_add_const_tensor
(
graph
->
GetCompilerHandle
(),
...
...
@@ -157,12 +157,31 @@ int ElementwiseConverter(void* ctx, OpLite* op, KernelBase* kernel) {
static_cast
<
const
char
*>
(
unique_op_name
.
c_str
()));
name
[
1
]
=
static_cast
<
const
char
*>
(
unique_op_name
.
c_str
());
dim
[
1
]
=
3
;
i_expand_shape_data
[
0
]
=
i_y_shape_data
[
0
]
;
i_expand_shape_data
[
1
]
=
1
;
i_expand_shape_data
[
2
]
=
1
;
i_expand_shape_data
.
push_back
(
i_y_shape_data
[
0
])
;
i_expand_shape_data
.
push_back
(
1
)
;
i_expand_shape_data
.
push_back
(
1
)
;
shape
[
1
]
=
&
i_expand_shape_data
[
0
];
y_data
=
nullptr
;
}
}
else
{
if
(
dim
[
1
]
<
dim
[
0
])
{
for
(
size_t
i
=
0
;
i
<
dim
[
1
];
i
++
)
{
i_expand_shape_data
.
push_back
(
i_y_shape_data
[
i
]);
}
for
(
size_t
i
=
dim
[
1
];
i
<
dim
[
0
];
i
++
)
{
i_expand_shape_data
.
push_back
(
1
);
}
add_reshape_layer_v2
(
graph
->
GetCompilerHandle
(),
name
[
1
],
shape
[
1
],
dim
[
1
],
static_cast
<
const
char
*>
(
unique_op_name
.
c_str
()),
const_cast
<
const
int
*>
(
&
i_expand_shape_data
[
0
]),
i_expand_shape_data
.
size
());
dim
[
1
]
=
dim
[
0
];
shape
[
1
]
=
&
i_expand_shape_data
[
0
];
name
[
1
]
=
static_cast
<
const
char
*>
(
unique_op_name
.
c_str
());
}
}
add_binary_layer_v2
(
graph
->
GetCompilerHandle
(),
name
[
0
],
...
...
lite/kernels/bm/bridges/multiclass_nms_op.cc
浏览文件 @
1d3754aa
...
...
@@ -51,7 +51,7 @@ int MultiClassNMSConverter(void* ctx, OpLite* op, KernelBase* kernel) {
auto
score_threshold
=
op_info
->
GetAttr
<
float
>
(
"score_threshold"
);
auto
nms_threshold
=
op_info
->
GetAttr
<
float
>
(
"nms_threshold"
);
auto
nms_eta
=
op_info
->
GetAttr
<
float
>
(
"nms_eta"
);
bool
normalized
;
bool
normalized
=
false
;
if
(
op_info
->
HasAttr
(
"normalized"
))
{
normalized
=
op_info
->
GetAttr
<
bool
>
(
"normalized"
);
}
...
...
@@ -97,12 +97,39 @@ int MultiClassNMSConverter(void* ctx, OpLite* op, KernelBase* kernel) {
in_dim
[
1
]
=
score_dims
.
size
();
in_name
[
0
]
=
static_cast
<
const
char
*>
(
boxes_var_name
.
c_str
());
in_name
[
1
]
=
static_cast
<
const
char
*>
(
score_var_name
.
c_str
());
int32_t
*
out_shape
[
1
];
int32_t
out_dim
[
1
];
const
char
*
out_name
[
1
];
int32_t
*
out_shape
[
2
];
int32_t
out_dim
[
2
];
const
char
*
out_name
[
2
];
out_shape
[
0
]
=
&
i_out_shape_data
[
0
];
out_dim
[
0
]
=
out_dims
.
size
();
out_name
[
0
]
=
static_cast
<
const
char
*>
(
out_var_name
.
c_str
());
std
::
vector
<
int64_t
>
vec_index_dim
(
score_dims
.
size
());
std
::
vector
<
int32_t
>
i_out_index_shape_data
(
score_dims
.
size
());
std
::
string
out_index_name
=
""
;
if
(
op_type
==
"multiclass_nms2"
)
{
output_num
=
2
;
out_index_name
=
op_info
->
Output
(
"Index"
).
front
();
auto
out_index
=
scope
->
FindVar
(
out_index_name
)
->
GetMutable
<
lite
::
Tensor
>
();
if
(
3
==
score_dims
.
size
())
{
vec_index_dim
[
0
]
=
score_dims
[
0
];
vec_index_dim
[
1
]
=
keep_top_k
;
vec_index_dim
[
2
]
=
1
;
}
else
{
vec_index_dim
[
0
]
=
keep_top_k
;
vec_index_dim
[
1
]
=
1
;
}
DDimLite
index_dims
(
vec_index_dim
);
out_index
->
Resize
(
index_dims
);
out_index
->
mutable_data
<
float
>
();
for
(
size_t
i
=
0
;
i
<
index_dims
.
size
();
i
++
)
{
i_out_index_shape_data
[
i
]
=
static_cast
<
int32_t
>
(
index_dims
[
i
]);
}
out_shape
[
1
]
=
&
i_out_index_shape_data
[
0
];
out_dim
[
1
]
=
index_dims
.
size
();
out_name
[
1
]
=
static_cast
<
const
char
*>
(
out_index_name
.
c_str
());
}
add_user_cpu_layer
(
graph
->
GetCompilerHandle
(),
input_num
,
in_shape
,
...
...
@@ -126,3 +153,6 @@ int MultiClassNMSConverter(void* ctx, OpLite* op, KernelBase* kernel) {
REGISTER_SUBGRAPH_BRIDGE
(
multiclass_nms
,
kBM
,
paddle
::
lite
::
subgraph
::
bm
::
MultiClassNMSConverter
);
REGISTER_SUBGRAPH_BRIDGE
(
multiclass_nms2
,
kBM
,
paddle
::
lite
::
subgraph
::
bm
::
MultiClassNMSConverter
);
lite/kernels/bm/bridges/paddle_use_bridges.h
浏览文件 @
1d3754aa
...
...
@@ -39,6 +39,7 @@ USE_SUBGRAPH_BRIDGE(norm, kBM);
USE_SUBGRAPH_BRIDGE
(
prior_box
,
kBM
);
USE_SUBGRAPH_BRIDGE
(
box_coder
,
kBM
);
USE_SUBGRAPH_BRIDGE
(
multiclass_nms
,
kBM
);
USE_SUBGRAPH_BRIDGE
(
multiclass_nms2
,
kBM
);
USE_SUBGRAPH_BRIDGE
(
nearest_interp
,
kBM
);
USE_SUBGRAPH_BRIDGE
(
bilinear_interp
,
kBM
);
USE_SUBGRAPH_BRIDGE
(
yolo_box
,
kBM
);
...
...
lite/kernels/bm/bridges/yolo_box_op.cc
浏览文件 @
1d3754aa
...
...
@@ -67,17 +67,17 @@ int YoloBoxConverter(void* ctx, OpLite* op, KernelBase* kernel) {
auto
downsample_ratio
=
op_info
->
GetAttr
<
int
>
(
"downsample_ratio"
);
auto
conf_thresh
=
op_info
->
GetAttr
<
float
>
(
"conf_thresh"
);
auto
anchors
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"anchors"
);
int
*
anchors_buffer
=
static_cast
<
int
*>
(
malloc
(
sizeof
(
int
)
*
anchors
.
size
()));
CHECK
(
anchors_buffer
!=
nullptr
);
memcpy
(
anchors_buffer
,
&
anchors
[
0
],
sizeof
(
int
)
*
anchors
.
size
());
CHECK_LE
(
anchors
.
size
(),
2000
);
user_cpu_param_t
bm_param
;
bm_param
.
op_type
=
USER_PADDLE_YOLO_BOX
;
bm_param
.
u
.
yolo_box_param
.
class_num
=
class_num
;
bm_param
.
u
.
yolo_box_param
.
downsample_ratio
=
downsample_ratio
;
bm_param
.
u
.
yolo_box_param
.
conf_thresh
=
conf_thresh
;
bm_param
.
u
.
yolo_box_param
.
anchors
=
anchors_buffer
;
memset
(
bm_param
.
u
.
yolo_box_param
.
anchors
,
0
,
2000
*
sizeof
(
int
));
memcpy
(
bm_param
.
u
.
yolo_box_param
.
anchors
,
&
anchors
[
0
],
anchors
.
size
()
*
sizeof
(
int
));
bm_param
.
u
.
yolo_box_param
.
anchors_size
=
anchors
.
size
();
memcpy
(
anchors_buffer
,
&
anchors
[
0
],
sizeof
(
int
)
*
anchors
.
size
());
int32_t
input_num
=
2
;
int32_t
output_num
=
2
;
int32_t
*
in_shape
[
2
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录