Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
ba02cfee
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
1 年多 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ba02cfee
编写于
12月 04, 2019
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix flops API.
上级
1cfa65ec
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
7 deletion
+14
-7
paddleslim/analysis/flops.py
paddleslim/analysis/flops.py
+14
-7
未找到文件。
paddleslim/analysis/flops.py
浏览文件 @
ba02cfee
...
...
@@ -18,33 +18,37 @@ from ..core import GraphWrapper
__all__
=
[
"flops"
]
def
flops
(
program
):
def
flops
(
program
,
detail
=
False
):
"""
Get FLOPS of target graph.
Args:
program(Program): The program used to calculate FLOPS.
"""
graph
=
GraphWrapper
(
program
)
return
_graph_flops
(
graph
)
return
_graph_flops
(
graph
,
detail
=
detail
)
def
_graph_flops
(
graph
,
only_conv
=
False
):
def
_graph_flops
(
graph
,
only_conv
=
False
,
detail
=
False
):
assert
isinstance
(
graph
,
GraphWrapper
)
flops
=
0
params2flops
=
{}
for
op
in
graph
.
ops
():
if
op
.
type
()
in
[
'conv2d'
,
'depthwise_conv2d'
]:
filter_shape
=
op
.
inputs
(
"Filter"
)[
0
].
shape
()
input_shape
=
op
.
inputs
(
"Input"
)[
0
].
shape
()
output_shape
=
op
.
outputs
(
"Output"
)[
0
].
shape
()
c_out
,
c_in
,
k_h
,
k_w
=
filter_shape
_
,
c_in
,
_
,
_
=
input_shape
c_out
,
_
,
k_h
,
k_w
=
filter_shape
_
,
_
,
h_out
,
w_out
=
output_shape
groups
=
op
.
attr
(
"groups"
)
kernel_ops
=
k_h
*
k_w
*
(
c_in
/
groups
)
kernel_ops
=
k_h
*
k_w
*
(
float
(
c_in
)
/
groups
)
if
len
(
op
.
inputs
(
"Bias"
))
>
0
:
with_bias
=
1
else
:
with_bias
=
0
flops
+=
2
*
h_out
*
w_out
*
c_out
*
(
kernel_ops
+
with_bias
)
op_flops
=
2
*
h_out
*
w_out
*
c_out
*
(
kernel_ops
+
with_bias
)
flops
+=
op_flops
params2flops
[
op
.
inputs
(
"Filter"
)[
0
].
name
()]
=
op_flops
elif
op
.
type
()
==
'pool2d'
and
not
only_conv
:
input_shape
=
op
.
inputs
(
"X"
)[
0
].
shape
()
output_shape
=
op
.
outputs
(
"Out"
)[
0
].
shape
()
...
...
@@ -65,4 +69,7 @@ def _graph_flops(graph, only_conv=False):
input_shape
[
0
]
=
1
flops
+=
np
.
product
(
input_shape
)
return
flops
if
detail
:
return
flops
,
params2flops
else
:
return
flops
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录