Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
3004ee86
M
mindspore
项目概览
正统之独孤求败
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3004ee86
编写于
8月 25, 2020
作者:
L
lyvette
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add activationType attr for pooling
add pooling-activation fusion pass modify
上级
b5ed5466
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
132 addition
and
2 deletion
+132
-2
mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.cc
...te/tools/converter/parser/tflite/tflite_pooling_parser.cc
+1
-0
mindspore/lite/tools/optimizer/common/gllo_utils.cc
mindspore/lite/tools/optimizer/common/gllo_utils.cc
+8
-0
mindspore/lite/tools/optimizer/common/gllo_utils.h
mindspore/lite/tools/optimizer/common/gllo_utils.h
+2
-0
mindspore/lite/tools/optimizer/fusion/conv_activation_fusion.cc
...ore/lite/tools/optimizer/fusion/conv_activation_fusion.cc
+1
-1
mindspore/lite/tools/optimizer/fusion/conv_activation_fusion.h
...pore/lite/tools/optimizer/fusion/conv_activation_fusion.h
+1
-1
mindspore/lite/tools/optimizer/fusion/pooling_activation_fusion.cc
.../lite/tools/optimizer/fusion/pooling_activation_fusion.cc
+79
-0
mindspore/lite/tools/optimizer/fusion/pooling_activation_fusion.h
...e/lite/tools/optimizer/fusion/pooling_activation_fusion.h
+40
-0
未找到文件。
mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.cc
浏览文件 @
3004ee86
...
...
@@ -70,6 +70,7 @@ STATUS TflitePoolingParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfli
attr
->
global
=
false
;
attr
->
roundMode
=
schema
::
RoundMode_FLOOR
;
attr
->
activationType
=
GetActivationFunctionType
(
tflite_attr
->
fused_activation_function
);
// calculate pad params
auto
data_index
=
tflite_op
->
inputs
[
0
];
...
...
mindspore/lite/tools/optimizer/common/gllo_utils.cc
浏览文件 @
3004ee86
...
...
@@ -346,6 +346,14 @@ bool IsConvNode(const BaseRef &n) {
return
false
;
}
bool
IsPoolingNode
(
const
BaseRef
&
n
)
{
if
(
utils
::
isa
<
CNodePtr
>
(
n
)
||
utils
::
isa
<
ValueNodePtr
>
(
n
))
{
auto
type
=
opt
::
GetCNodeType
(
n
);
return
type
==
schema
::
PrimitiveType_Pooling
;
}
return
false
;
}
bool
CheckIsAllInputsParam
(
const
AnfNodePtr
&
node
)
{
if
(
utils
::
isa
<
CNode
>
(
node
))
{
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
...
...
mindspore/lite/tools/optimizer/common/gllo_utils.h
浏览文件 @
3004ee86
...
...
@@ -56,6 +56,8 @@ bool IsParamNode(const BaseRef &n);
bool
IsConvNode
(
const
BaseRef
&
n
);
bool
IsPoolingNode
(
const
BaseRef
&
n
);
bool
CheckIsAllInputsParam
(
const
AnfNodePtr
&
node
);
size_t
GetOutputTensorNum
(
const
AnfNodePtr
&
node
);
...
...
mindspore/lite/tools/optimizer/fusion/conv_activation_fusion.cc
浏览文件 @
3004ee86
...
...
@@ -6,7 +6,7 @@
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
conv_activation_fusion.h
*
* 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.
...
...
mindspore/lite/tools/optimizer/fusion/conv_activation_fusion.h
浏览文件 @
3004ee86
...
...
@@ -6,7 +6,7 @@
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
conv_activation_fusion.h
*
* 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.
...
...
mindspore/lite/tools/optimizer/fusion/pooling_activation_fusion.cc
0 → 100644
浏览文件 @
3004ee86
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* 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 "tools/optimizer/fusion/pooling_activation_fusion.h"
#include <memory>
#include "src/ops/primitive_c.h"
#include "src/ops/pooling.h"
#include "src/ops/activation.h"
#include "schema/inner/model_generated.h"
#include "tools/optimizer/common/gllo_utils.h"
namespace
mindspore
::
opt
{
namespace
{
constexpr
size_t
kActivationInputsLength
=
2
;
}
const
BaseRef
PoolingActivationFusion
::
DefinePattern
()
const
{
auto
pooling_var
=
std
::
make_shared
<
CondVar
>
(
IsPoolingNode
)();
auto
prim
=
new
schema
::
PrimitiveT
();
if
(
prim
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"new primitiveT failed"
;
return
nullptr
;
}
prim
->
value
.
type
=
primitive_type
;
auto
prim_value
=
std
::
make_shared
<
lite
::
PrimitiveC
>
(
prim
);
return
VectorRef
({
prim_value
,
pooling_var
});
}
const
AnfNodePtr
PoolingActivationFusion
::
Process
(
const
FuncGraphPtr
&
func_graph
,
const
AnfNodePtr
&
node
,
const
EquivPtr
&
)
const
{
MS_LOG
(
DEBUG
)
<<
"pooling activation pass process:"
<<
schema
::
EnumNamesPrimitiveType
()[
primitive_type
];
CheckIfFuncGraphIsNull
(
func_graph
);
CheckIfAnfNodeIsNull
(
node
);
auto
act_node
=
node
->
cast
<
CNodePtr
>
();
CheckIfCNodeIsNull
(
act_node
);
CheckInputSize
(
act_node
,
kActivationInputsLength
);
auto
primitivec
=
GetValueNode
<
std
::
shared_ptr
<
lite
::
PrimitiveC
>>
(
act_node
->
input
(
0
));
MS_ASSERT
(
utils
::
isa
<
std
::
shared_ptr
<
mindspore
::
lite
::
Activation
>>
(
primitivec
));
auto
act_primitivec
=
utils
::
cast
<
std
::
shared_ptr
<
mindspore
::
lite
::
Activation
>>
(
primitivec
);
MS_ASSERT
(
act_primitivec
!=
nullptr
);
if
(
act_primitivec
->
GetType
()
!=
activation_type
)
{
return
node
;
}
AnfNodePtr
pre_node
=
act_node
->
input
(
1
);
CheckIfAnfNodeIsNull
(
pre_node
);
if
(
pre_node
!=
nullptr
&&
pre_node
->
isa
<
CNode
>
())
{
if
(
IsMultiOutputTensors
(
func_graph
,
pre_node
))
{
return
node
;
}
auto
pooling_node
=
pre_node
->
cast
<
CNodePtr
>
();
auto
primitive_c
=
GetValueNode
<
std
::
shared_ptr
<
lite
::
PrimitiveC
>>
(
pooling_node
->
input
(
0
));
MS_ASSERT
(
primitive_c
);
MS_ASSERT
(
utils
::
isa
<
std
::
shared_ptr
<
mindspore
::
lite
::
Pooling
>>
(
primitive_c
));
auto
primc
=
utils
::
cast
<
std
::
shared_ptr
<
mindspore
::
lite
::
Pooling
>>
(
primitive_c
);
MS_ASSERT
(
primc
!=
nullptr
);
if
(
primc
->
GetActivationType
()
==
schema
::
ActivationType_NO_ACTIVATION
)
{
primc
->
SetActivationType
(
activation_type
);
return
pre_node
;
}
}
return
node
;
}
}
// namespace mindspore::opt
mindspore/lite/tools/optimizer/fusion/pooling_activation_fusion.h
0 → 100644
浏览文件 @
3004ee86
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* 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.
*/
#ifndef MINDSPORE_LITE_SRC_PASS_FUSION_POOLING_ACTIVATION_FUSION_H_
#define MINDSPORE_LITE_SRC_PASS_FUSION_POOLING_ACTIVATION_FUSION_H_
#include <string>
#include "backend/optimizer/common/optimizer.h"
#include "schema/inner/model_generated.h"
namespace
mindspore
{
namespace
opt
{
class
PoolingActivationFusion
:
public
PatternProcessPass
{
public:
explicit
PoolingAActivationFusion
(
bool
multigraph
=
true
,
const
std
::
string
&
name
=
"pooling_activation_fusion"
,
schema
::
PrimitiveType
primitive
=
schema
::
PrimitiveType_LeakyReLU
,
schema
::
ActivationType
activation
=
schema
::
ActivationType_LEAKY_RELU
)
:
PatternProcessPass
(
name
,
multigraph
),
primitive_type
(
primitive
),
activation_type
(
activation
)
{}
~
PoolingAActivationFusion
()
override
=
default
;
const
BaseRef
DefinePattern
()
const
override
;
const
AnfNodePtr
Process
(
const
FuncGraphPtr
&
,
const
AnfNodePtr
&
,
const
EquivPtr
&
)
const
override
;
schema
::
PrimitiveType
primitive_type
;
schema
::
ActivationType
activation_type
;
};
}
// namespace opt
}
// namespace mindspore
#endif // MINDSPORE_LITE_SRC_PASS_FUSION_POOLING_ACTIVATION_FUSION_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录