Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
6e332d3f
M
models
项目概览
PaddlePaddle
/
models
大约 2 年 前同步成功
通知
232
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6e332d3f
编写于
10月 22, 2019
作者:
L
Liufang Sang
提交者:
whs
10月 22, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[PaddleSlim] add skip_quant test in doc (#3719)
上级
3082e40a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
2 deletion
+45
-2
PaddleSlim/classification/models/resnet.py
PaddleSlim/classification/models/resnet.py
+3
-2
PaddleSlim/classification/quantization/README.md
PaddleSlim/classification/quantization/README.md
+32
-0
PaddleSlim/classification/quantization/compress.py
PaddleSlim/classification/quantization/compress.py
+10
-0
未找到文件。
PaddleSlim/classification/models/resnet.py
浏览文件 @
6e332d3f
...
...
@@ -44,6 +44,8 @@ class ResNet():
# TODO(wanghaoshuang@baidu.com):
# fix name("conv1") conflict between student and teacher in distillation.
#with fluid.name_scope('skip_quant'):
conv
=
self
.
conv_bn_layer
(
input
=
input
,
num_filters
=
64
,
...
...
@@ -51,8 +53,7 @@ class ResNet():
stride
=
2
,
act
=
'relu'
,
name
=
prefix_name
+
conv1_name
)
with
fluid
.
name_scope
(
"skip_quant"
):
conv
=
fluid
.
layers
.
pool2d
(
conv
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
pool_size
=
3
,
pool_stride
=
2
,
...
...
PaddleSlim/classification/quantization/README.md
浏览文件 @
6e332d3f
...
...
@@ -159,6 +159,38 @@ python infer.py \
### PaddleLite预测
FP32模型可使用Paddle-Lite进行加载预测,可参见教程
[
Paddle-Lite如何加载运行量化模型
](
https://github.com/PaddlePaddle/Paddle-Lite/wiki/model_quantization
)
。
## 如何进行部分量化
通过在定义op时指定
``name_scope``
为
``skip_quant``
可对这个op跳过量化。比如在
<a
href=
"../models/resnet.py"
>
PaddleSlim/classification/models/resnet.py
</a>
中,将某个conv的定义作如下改变:
原定义:
```
conv = self.conv_bn_layer(
input=input,
num_filters=64,
filter_size=7,
stride=2,
act='relu',
name=prefix_name + conv1_name)
```
跳过量化时的定义:
```
with fluid.name_scope('skip_quant'):
conv = self.conv_bn_layer(
input=input,
num_filters=64,
filter_size=7,
stride=2,
act='relu',
name=prefix_name + conv1_name)
```
在脚本
<a
href=
"./compress.py"
>
PaddleSlim/classification/quantization/compress.py
</a>
中,统计了
``conv``
op的数量和以
``fake_quantize``
开头的量化op的数量,在对一些
``conv``
op跳过之后,可发现以
``fake_quantize``
开头的量化op的数量变少。
## 示例结果
...
...
PaddleSlim/classification/quantization/compress.py
浏览文件 @
6e332d3f
...
...
@@ -99,6 +99,16 @@ def compress(args):
distiller_optimizer
=
None
)
com_pass
.
config
(
args
.
config_file
)
com_pass
.
run
()
conv_op_num
=
0
fake_quant_op_num
=
0
for
op
in
com_pass
.
context
.
eval_graph
.
ops
():
if
op
.
_op
.
type
==
'conv2d'
:
conv_op_num
+=
1
elif
op
.
_op
.
type
.
startswith
(
'fake_quantize'
):
fake_quant_op_num
+=
1
print
(
'conv op num {}'
.
format
(
conv_op_num
))
print
(
'fake quant op num {}'
.
format
(
fake_quant_op_num
))
def
main
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录