Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
e1238c16
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看板
提交
e1238c16
编写于
8月 18, 2018
作者:
xiebaiyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dd preluop support genet && add unit test close
#799
上级
1a39278f
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
125 addition
and
72 deletion
+125
-72
src/common/types.cpp
src/common/types.cpp
+5
-1
src/common/types.h
src/common/types.h
+2
-0
src/operators/conv_transpose_op.cpp
src/operators/conv_transpose_op.cpp
+9
-0
src/operators/conv_transpose_op.h
src/operators/conv_transpose_op.h
+10
-0
src/operators/kernel/arm/prelu_kernel.cpp
src/operators/kernel/arm/prelu_kernel.cpp
+29
-67
src/operators/op_param.h
src/operators/op_param.h
+14
-4
test/CMakeLists.txt
test/CMakeLists.txt
+4
-0
test/net/test_genet_combine.cpp
test/net/test_genet_combine.cpp
+51
-0
test/test_helper.h
test/test_helper.h
+1
-0
未找到文件。
src/common/types.cpp
浏览文件 @
e1238c16
...
...
@@ -51,6 +51,8 @@ const char *G_OP_TYPE_FUSION_ELEMENTWISE_ADD_RELU =
const
char
*
G_OP_TYPE_FUSION_FC_RELU
=
"fusion_fc_relu"
;
const
char
*
G_OP_TYPE_REGION
=
"region"
;
const
char
*
G_OP_TYPE_FUSION_CONV_BN
=
"fusion_conv_bn"
;
const
char
*
G_OP_TYPE_CONV_TRANSPOSE
=
"conv2d_transpose"
;
const
char
*
G_OP_TYPE_PRELU
=
"prelu"
;
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
...
...
@@ -58,6 +60,7 @@ std::unordered_map<
{
G_OP_TYPE_CONV
,
{{
"Input"
},
{
"Output"
}}},
{
G_OP_TYPE_FUSION_DWCONV_BN_RELU
,
{{
"Input"
},
{
"Out"
}}},
{
G_OP_TYPE_FUSION_CONV_BN_RELU
,
{{
"Input"
},
{
"Out"
}}},
{
G_OP_TYPE_PRELU
,
{{
"X"
,
"Alpha"
},
{
"Out"
}}},
{
G_OP_TYPE_FUSION_CONV_ADD
,
{{
"Input"
},
{
"Out"
}}},
{
G_OP_TYPE_RELU
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_SOFTMAX
,
{{
"X"
},
{
"Out"
}}},
...
...
@@ -87,6 +90,7 @@ std::unordered_map<
{
G_OP_TYPE_FUSION_ELEMENTWISE_ADD_RELU
,
{{
"X"
,
"Y"
},
{
"Out"
}}},
{
G_OP_TYPE_FUSION_FC_RELU
,
{{
"X"
,
"Y"
,
"Z"
},
{
"Out"
}}},
{
G_OP_TYPE_REGION
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_FUSION_CONV_BN
,
{{
"Input"
},
{
"Y"
}}}};
{
G_OP_TYPE_FUSION_CONV_BN
,
{{
"Input"
},
{
"Y"
}}},
{
G_OP_TYPE_CONV_TRANSPOSE
,
{{
"Input"
},
{
"Output"
}}}};
}
// namespace paddle_mobile
src/common/types.h
浏览文件 @
e1238c16
...
...
@@ -114,6 +114,8 @@ extern const char *G_OP_TYPE_FUSION_ELEMENTWISE_ADD_RELU;
extern
const
char
*
G_OP_TYPE_FUSION_FC_RELU
;
extern
const
char
*
G_OP_TYPE_REGION
;
extern
const
char
*
G_OP_TYPE_FUSION_CONV_BN
;
extern
const
char
*
G_OP_TYPE_CONV_TRANSPOSE
;
extern
const
char
*
G_OP_TYPE_PRELU
;
extern
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
...
...
src/operators/conv_transpose_op.cpp
浏览文件 @
e1238c16
...
...
@@ -20,4 +20,13 @@ namespace paddle_mobile {
namespace
operators
{}
}
// namespace paddle_mobile
namespace
ops
=
paddle_mobile
::
operators
;
#ifdef PADDLE_MOBILE_CPU
REGISTER_OPERATOR_CPU
(
conv2d_transpose
,
ops
::
ConvOpTranspose
);
#endif
#ifdef PADDLE_MOBILE_MALI_GPU
#endif
#ifdef PADDLE_MOBILE_FPGA
#endif
#endif
src/operators/conv_transpose_op.h
浏览文件 @
e1238c16
...
...
@@ -88,4 +88,14 @@ class ConvOpTranspose : public framework::OperatorWithKernel<
}
// namespace operators
}
// namespace paddle_mobile
#ifdef PADDLE_MOBILE_CPU
USE_OP_CPU
(
conv2d_transpose
);
#endif
#ifdef PADDLE_MOBILE_MALI_GPU
USE_OP_MALI_GPU
(
conv2d_transpose
);
#endif
#ifdef PADDLE_MOBILE_FPGA
USE_OP_FPGA
(
conv2d_transpose
);
#endif
#endif
src/operators/kernel/arm/prelu_kernel.cpp
浏览文件 @
e1238c16
...
...
@@ -33,77 +33,39 @@ struct PReluFunctor {
* */
template
<
>
void
PReluKernel
<
CPU
,
float
>::
Compute
(
const
PReluParam
&
param
)
const
{
const
auto
*
input_x
=
param
.
InputX
();
auto
*
input_x_ptr
=
input_x
->
data
<
float
>
();
auto
*
out
=
param
.
Out
();
auto
*
out_ptr
=
out
->
mutable_data
<
float
>
();
if
(
param
.
Slopes
().
size
()
==
1
)
{
PReluFunctor
<
float
>
func_
(
param
.
Slopes
()[
0
]);
math
::
Transform
trans
;
trans
(
input_x_ptr
,
input_x_ptr
+
input_x
->
numel
(),
out_ptr
,
func_
);
}
else
if
(
param
.
Slopes
().
size
()
>
1
)
{
const
int
dim_size
=
input_x
->
dims
().
size
();
switch
(
dim_size
)
{
case
0
:
break
;
case
1
:
{
const
int
input_width
=
input_x
->
dims
()[
0
];
math
::
Transform
trans
;
DLOG
<<
"PReluKernel :Compute"
;
#pragma omp parallel for
for
(
int
w
=
0
;
w
<
input_width
;
++
w
)
{
out_ptr
[
w
]
=
input_x_ptr
[
w
]
*
param
.
Slopes
()[
w
];
}
}
break
;
case
2
:
{
const
int
input_height
=
input_x
->
dims
()[
0
];
const
int
input_width
=
input_x
->
dims
()[
1
];
auto
*
x
=
param
.
InputX
();
auto
*
alpha
=
param
.
InputAlpha
();
auto
*
out
=
param
.
Out
();
std
::
string
mode
=
param
.
Mode
();
const
auto
*
x_ptr
=
x
->
data
<
float
>
();
auto
*
o_ptr
=
out
->
mutable_data
<
float
>
();
const
auto
*
alpha_ptr
=
alpha
->
data
<
float
>
();
int
numel
=
x
->
numel
();
auto
dim
=
x
->
dims
();
int
index
=
0
;
int
i
=
0
;
int
temp
=
0
;
if
(
mode
==
"channel"
)
{
#pragma omp parallel for
math
::
Transform
trans
;
#pragma omp parallel for
for
(
int
h
=
0
;
h
<
input_height
;
++
h
)
{
PReluFunctor
<
float
>
func_
(
param
.
Slopes
()[
h
]);
const
float
*
ptr
=
input_x_ptr
+
h
*
input_width
;
float
*
optr
=
out_ptr
+
+
h
*
input_width
;
trans
(
ptr
,
ptr
+
input_width
,
optr
,
func_
);
}
}
break
;
case
3
:
{
const
int
chan_size
=
input_x
->
dims
()[
0
];
const
int
input_height
=
input_x
->
dims
()[
1
];
const
int
input_width
=
input_x
->
dims
()[
2
];
for
(
i
=
0
;
i
<
numel
;
i
++
)
{
temp
=
numel
/
(
dim
[
0
]
*
dim
[
1
]);
index
=
(
i
/
temp
)
%
dim
[
1
];
o_ptr
[
i
]
=
x_ptr
[
i
]
>
0
?
x_ptr
[
i
]
:
alpha_ptr
[
index
]
*
x_ptr
[
i
];
}
}
else
if
(
mode
==
"element"
)
{
#pragma omp parallel for
math
::
Transform
trans
;
#pragma omp parallel for
for
(
int
c
=
0
;
c
<
chan_size
;
++
c
)
{
PReluFunctor
<
float
>
func_
(
param
.
Slopes
()[
c
]);
int
size
=
input_height
*
input_width
;
const
float
*
ptr
=
input_x_ptr
+
c
*
size
;
float
*
optr
=
out_ptr
+
c
*
size
;
trans
(
ptr
,
ptr
+
size
,
optr
,
func_
);
}
}
break
;
case
4
:
default:
{
const
int
batch_size
=
input_x
->
dims
()[
0
];
const
int
chan_size
=
input_x
->
dims
()[
1
];
const
int
input_height
=
input_x
->
dims
()[
2
];
const
int
input_width
=
input_x
->
dims
()[
3
];
math
::
Transform
trans
;
for
(
i
=
0
;
i
<
numel
;
i
++
)
{
o_ptr
[
i
]
=
x_ptr
[
i
]
>
0
?
x_ptr
[
i
]
:
alpha_ptr
[
i
]
*
x_ptr
[
i
];
}
}
else
{
#pragma omp parallel for
#pragma omp parallel for
for
(
int
b
=
0
;
b
<
batch_size
;
++
b
)
{
for
(
int
c
=
0
;
c
<
chan_size
;
++
c
)
{
PReluFunctor
<
float
>
func_
(
param
.
Slopes
()[
c
]);
int
size
=
input_height
*
input_width
;
const
float
*
ptr
=
input_x_ptr
+
b
*
c
*
size
;
float
*
optr
=
out_ptr
+
+
b
*
c
*
size
;
trans
(
ptr
,
ptr
+
size
,
optr
,
func_
);
}
}
}
// case 3,default
break
;
for
(
i
=
0
;
i
<
numel
;
i
++
)
{
o_ptr
[
i
]
=
x_ptr
[
i
]
>
0
?
x_ptr
[
i
]
:
alpha_ptr
[
0
]
*
x_ptr
[
i
];
}
}
}
...
...
src/operators/op_param.h
浏览文件 @
e1238c16
...
...
@@ -39,6 +39,11 @@ using std::vector;
class
OpParam
{
protected:
template
<
typename
T
>
static
T
*
InputAlphaFrom
(
const
VariableNameMap
&
inputs
,
const
Scope
&
scope
)
{
return
GetVarValue
<
T
>
(
"Alpha"
,
inputs
,
scope
);
}
template
<
typename
T
>
static
T
*
InputFrom
(
const
VariableNameMap
&
inputs
,
const
Scope
&
scope
)
{
return
GetVarValue
<
T
>
(
"Input"
,
inputs
,
scope
);
...
...
@@ -890,19 +895,24 @@ class PReluParam : public OpParam {
public:
PReluParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
DLOG
<<
"PReluParam inputs before"
;
input_x_
=
InputXFrom
<
LoDTensor
>
(
inputs
,
scope
);
alpha_
=
InputAlphaFrom
<
LoDTensor
>
(
inputs
,
scope
);
framework
::
DDim
dims
=
alpha_
->
dims
();
out_
=
OutFrom
<
LoDTensor
>
(
outputs
,
scope
);
slopes_
=
GetAttr
<
vector
<
float
>>
(
"slopes"
,
attrs
);
mode_
=
GetAttr
<
std
::
string
>
(
"mode"
,
attrs
);
DLOG
<<
"PReluParam mode after"
<<
mode_
;
}
const
Tensor
*
InputX
()
const
{
return
input_x_
;
}
const
Tensor
*
InputAlpha
()
const
{
return
alpha_
;
}
Tensor
*
Out
()
const
{
return
out_
;
}
const
vector
<
float
>
&
Slopes
()
const
{
return
slopes
_
;
}
const
std
::
string
&
Mode
()
const
{
return
mode
_
;
}
private:
Tensor
*
input_x_
;
Tensor
*
out_
;
vector
<
float
>
slopes_
;
Tensor
*
alpha_
;
std
::
string
mode_
;
};
#endif
...
...
test/CMakeLists.txt
浏览文件 @
e1238c16
...
...
@@ -155,6 +155,10 @@ else ()
ADD_EXECUTABLE
(
test-mobilenet-combine net/test_mobilenet_combine.cpp test_helper.h test_include.h executor_for_test.h
)
target_link_libraries
(
test-mobilenet-combine paddle-mobile
)
# gen test
ADD_EXECUTABLE
(
test-genet net/test_genet_combine.cpp test_helper.h test_include.h executor_for_test.h
)
target_link_libraries
(
test-genet paddle-mobile
)
# gen test
ADD_EXECUTABLE
(
test-sigmoid operators/test_sigmoid_op.cpp test_include.h
)
target_link_libraries
(
test-sigmoid paddle-mobile
)
...
...
test/net/test_genet_combine.cpp
0 → 100644
浏览文件 @
e1238c16
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <iostream>
#include "../test_helper.h"
#include "../test_include.h"
int
main
()
{
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
CPU
>
paddle_mobile
;
paddle_mobile
.
SetThreadNum
(
4
);
auto
time1
=
time
();
if
(
paddle_mobile
.
Load
(
std
::
string
(
g_genet_combine
)
+
"/model"
,
std
::
string
(
g_genet_combine
)
+
"/params"
,
true
))
{
auto
time2
=
time
();
std
::
cout
<<
"load cost :"
<<
time_diff
(
time1
,
time1
)
<<
"ms"
<<
std
::
endl
;
std
::
vector
<
float
>
input
;
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
128
,
128
};
GetInput
<
float
>
(
g_test_image_1x3x224x224_banana
,
&
input
,
dims
);
// 预热一次
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
std
::
vector
<
float
>::
iterator
biggest
=
std
::
max_element
(
std
::
begin
(
vec_result
),
std
::
end
(
vec_result
));
std
::
cout
<<
" Max element is "
<<
*
biggest
<<
" at position "
<<
std
::
distance
(
std
::
begin
(
vec_result
),
biggest
)
<<
std
::
endl
;
auto
time3
=
time
();
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
}
auto
time4
=
time
();
std
::
cout
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
/
10
<<
"ms"
<<
std
::
endl
;
}
std
::
cout
<<
"如果结果Nan请查看: test/images/test_image_1x3x224x224_float 是否存在?"
<<
std
::
endl
;
return
0
;
}
test/test_helper.h
浏览文件 @
e1238c16
...
...
@@ -26,6 +26,7 @@ limitations under the License. */
static
const
char
*
g_ocr
=
"../models/ocr"
;
static
const
char
*
g_mobilenet_ssd
=
"../models/mobilenet+ssd"
;
static
const
char
*
g_genet_combine
=
"../models/enet"
;
static
const
char
*
g_mobilenet_ssd_gesture
=
"../models/mobilenet+ssd_gesture"
;
static
const
char
*
g_mobilenet_combined
=
"../models/mobilenet_combine"
;
static
const
char
*
g_mobilenet_detect
=
"../models/mobilenet-detect"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录