Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
d397aed5
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
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看板
提交
d397aed5
编写于
4月 01, 2020
作者:
C
chenjiaoAngel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add conv_transpose+bn fusion. test=develop
上级
baa4ff00
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
3 deletion
+51
-3
lite/core/mir/fusion/conv_bn_fuse_pass.cc
lite/core/mir/fusion/conv_bn_fuse_pass.cc
+3
-1
lite/core/mir/fusion/conv_bn_fuser.cc
lite/core/mir/fusion/conv_bn_fuser.cc
+48
-2
未找到文件。
lite/core/mir/fusion/conv_bn_fuse_pass.cc
浏览文件 @
d397aed5
...
...
@@ -26,10 +26,12 @@ namespace mir {
void
ConvBNFusePass
::
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
{
// initialze fuser params
std
::
vector
<
bool
>
conv_has_bias_cases
{
true
,
false
};
std
::
vector
<
std
::
string
>
conv_type_cases
{
"conv2d"
,
"depthwise_conv2d"
};
std
::
vector
<
std
::
string
>
conv_type_cases
{
"conv2d"
,
"depthwise_conv2d"
,
"conv2d_transpose"
};
// start fuse using params
for
(
auto
conv_has_bias
:
conv_has_bias_cases
)
{
for
(
auto
conv_type
:
conv_type_cases
)
{
std
::
cout
<<
"conv_has_bias:"
<<
conv_has_bias
<<
" conv_type:"
<<
conv_type
<<
std
::
endl
;
VLOG
(
4
)
<<
"conv_has_bias:"
<<
conv_has_bias
<<
" conv_type:"
<<
conv_type
;
fusion
::
ConvBNFuser
fuser
(
conv_type
,
conv_has_bias
);
...
...
lite/core/mir/fusion/conv_bn_fuser.cc
浏览文件 @
d397aed5
...
...
@@ -153,7 +153,7 @@ void ConvBNFuser::InsertNewNode(SSAGraph* graph, const key2nodes_t& matched) {
// compute new conv_weight for int8
auto
weight_scale
=
conv_op_desc
->
GetAttr
<
std
::
vector
<
float
>>
(
"weight_scale"
);
for
(
unsigned
int
i
=
0
;
i
<
h
;
++
i
)
{
/*
for (unsigned int i = 0; i < h; ++i) {
weight_scale[i] *= fabsf(alpha_data[i]);
if (alpha_data[i] < 0.f) {
auto ptr_row = conv_weight_d + i * w;
...
...
@@ -162,6 +162,33 @@ void ConvBNFuser::InsertNewNode(SSAGraph* graph, const key2nodes_t& matched) {
}
}
}
*/
if
(
conv_type_
==
"conv2d_transpose"
)
{
int
c_size
=
conv_weight_t
->
dims
()[
1
]
*
conv_weight_t
->
dims
()[
2
]
*
conv_weight_t
->
dims
()[
3
];
int
hw
=
conv_weight_t
->
dims
()[
2
]
*
conv_weight_t
->
dims
()[
3
];
for
(
unsigned
int
k
=
0
;
k
<
conv_weight_t
->
dims
()[
0
];
++
k
)
{
for
(
unsigned
int
i
=
0
;
i
<
h
;
++
i
)
{
weight_scale
[
i
]
*=
fabsf
(
alpha_data
[
i
]);
if
(
alpha_data
[
i
]
<
0.
f
)
{
auto
ptr_row
=
conv_weight_d
+
k
*
c_size
+
i
*
hw
;
for
(
unsigned
int
j
=
0
;
j
<
hw
;
++
j
)
{
ptr_row
[
j
]
*=
-
1
;
}
}
}
}
}
else
{
for
(
unsigned
int
i
=
0
;
i
<
h
;
++
i
)
{
weight_scale
[
i
]
*=
fabsf
(
alpha_data
[
i
]);
if
(
alpha_data
[
i
]
<
0.
f
)
{
auto
ptr_row
=
conv_weight_d
+
i
*
w
;
for
(
unsigned
int
j
=
0
;
j
<
w
;
++
j
)
{
ptr_row
[
j
]
*=
-
1
;
}
}
}
}
conv_op_desc
->
SetAttr
(
"weight_scale"
,
weight_scale
);
}
else
if
(
is_weight_quantization
)
{
std
::
string
scale_name
=
conv_weight_name
+
"_quant_scale"
;
...
...
@@ -176,10 +203,29 @@ void ConvBNFuser::InsertNewNode(SSAGraph* graph, const key2nodes_t& matched) {
}
else
{
// compute new conv_weight
auto
conv_weight_d
=
conv_weight_t
->
mutable_data
<
float
>
();
for
(
unsigned
int
i
=
0
;
i
<
h
;
++
i
)
{
// n: conv2d output channels
/*
for (unsigned int i = 0; i < h; ++i) { // n: conv2d output channels
for (unsigned int j = 0; j < w; ++j) { // w: conv2d input channels
conv_weight_d[i * w + j] *= alpha_data[i];
}
}*/
if
(
conv_type_
==
"conv2d_transpose"
)
{
int
c_size
=
conv_weight_t
->
dims
()[
1
]
*
conv_weight_t
->
dims
()[
2
]
*
conv_weight_t
->
dims
()[
3
];
int
hw
=
conv_weight_t
->
dims
()[
2
]
*
conv_weight_t
->
dims
()[
3
];
for
(
unsigned
int
k
=
0
;
k
<
conv_weight_t
->
dims
()[
0
];
++
k
)
{
for
(
unsigned
int
i
=
0
;
i
<
h
;
++
i
)
{
auto
ptr_row
=
conv_weight_d
+
k
*
c_size
+
i
*
hw
;
for
(
unsigned
int
j
=
0
;
j
<
hw
;
++
j
)
{
ptr_row
[
j
]
*=
alpha_data
[
i
];
}
}
}
}
else
{
for
(
unsigned
int
i
=
0
;
i
<
h
;
++
i
)
{
// n: conv2d output channels
for
(
unsigned
int
j
=
0
;
j
<
w
;
++
j
)
{
// w: conv2d input channels
conv_weight_d
[
i
*
w
+
j
]
*=
alpha_data
[
i
];
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录