Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
3a9ed427
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看板
未验证
提交
3a9ed427
编写于
7月 13, 2021
作者:
X
XGZhang
提交者:
GitHub
7月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update quant docs (#841)
* update quant docs * Update quantization_api.rst
上级
068119c9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
130 addition
and
42 deletion
+130
-42
docs/zh_cn/api_cn/static/quant/quantization_api.rst
docs/zh_cn/api_cn/static/quant/quantization_api.rst
+61
-24
docs/zh_cn/tutorials/quant/static/quant_post_tutorial.md
docs/zh_cn/tutorials/quant/static/quant_post_tutorial.md
+69
-18
未找到文件。
docs/zh_cn/api_cn/static/quant/quantization_api.rst
浏览文件 @
3a9ed427
...
@@ -74,16 +74,35 @@ quant_post_dynamic
...
@@ -74,16 +74,35 @@ quant_post_dynamic
..
warning
::
..
warning
::
此
示例不能直接运行,因为需要加载 ``${model_dir}`` 下的模型,所以不能直接运行
。
此
api
需要加载
``${
model_path
}``
下的模型,所以示例中首先导出了
inference
model
。
..
code
-
block
::
python
..
code
-
block
::
python
import
paddle
import
paddle
import
paddle
.
fluid
as
fluid
import
paddle
.
fluid
as
fluid
import
paddle
.
dataset
.
mnist
as
reader
import
paddle
.
dataset
.
mnist
as
reader
from
paddleslim
.
models
import
MobileNet
from
paddleslim
.
quant
import
quant_post_dynamic
from
paddleslim
.
quant
import
quant_post_dynamic
paddle
.
enable_static
()
paddle
.
enable_static
()
image
=
paddle
.
static
.
data
(
name
=
'image'
,
shape
=[
None
,
1
,
28
,
28
],
dtype
=
'float32'
)
model
=
MobileNet
()
out
=
model
.
net
(
input
=
image
,
class_dim
=
10
)
main_prog
=
paddle
.
static
.
default_main_program
()
val_prog
=
main_prog
.
clone
(
for_test
=
True
)
place
=
paddle
.
CUDAPlace
(
0
)
if
paddle
.
is_compiled_with_cuda
()
else
paddle
.
CPUPlace
()
exe
=
paddle
.
static
.
Executor
(
place
)
exe
.
run
(
paddle
.
static
.
default_startup_program
())
paddle
.
fluid
.
io
.
save_inference_model
(
dirname
=
'./model_path'
,
feeded_var_names
=[
image
.
name
],
target_vars
=[
out
],
main_program
=
val_prog
,
executor
=
exe
,
model_filename
=
'__model__'
,
params_filename
=
'__params__'
)
quant_post_dynamic
(
quant_post_dynamic
(
model_dir
=
'./model_path'
,
model_dir
=
'./model_path'
,
save_model_dir
=
'./save_path'
,
save_model_dir
=
'./save_path'
,
...
@@ -164,29 +183,48 @@ quant_post_static
...
@@ -164,29 +183,48 @@ quant_post_static
..
warning
::
..
warning
::
此
示例不能直接运行,因为需要加载 ``${model_dir}`` 下的模型,所以不能直接运行
。
此
api
需要加载
``${
model_path
}``
下的模型,所以示例中首先导出了
inference
model
。
..
code
-
block
::
python
..
code
-
block
::
python
import paddle
import
paddle
import paddle.fluid as fluid
import
paddle
.
fluid
as
fluid
import paddle.dataset.mnist as reader
import
paddle
.
dataset
.
mnist
as
reader
from paddleslim.quant import quant_post_static
from
paddleslim
.
models
import
MobileNet
paddle.enable_static()
from
paddleslim
.
quant
import
quant_post_static
val_reader = reader.train()
use_gpu = True
paddle
.
enable_static
()
place = fluid.CUDAPlace(0) if use_gpu else fluid.CPUPlace()
val_reader
=
reader
.
test
()
use_gpu
=
True
exe = fluid.Executor(place)
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
quant_post_static(
exe
=
fluid
.
Executor
(
place
)
executor=exe,
paddle
.
enable_static
()
model_dir='./model_path',
image
=
paddle
.
static
.
data
(
name
=
'image'
,
shape
=[
None
,
1
,
28
,
28
],
dtype
=
'float32'
)
quantize_model_path='./save_path',
model
=
MobileNet
()
sample_generator=val_reader,
out
=
model
.
net
(
input
=
image
,
class_dim
=
10
)
model_filename='__model__',
main_prog
=
paddle
.
static
.
default_main_program
()
params_filename='__params__',
val_prog
=
main_prog
.
clone
(
for_test
=
True
)
batch_size=16,
place
=
paddle
.
CUDAPlace
(
0
)
if
paddle
.
is_compiled_with_cuda
()
else
paddle
.
CPUPlace
()
batch_nums=10)
exe
=
paddle
.
static
.
Executor
(
place
)
exe
.
run
(
paddle
.
static
.
default_startup_program
())
paddle
.
fluid
.
io
.
save_inference_model
(
dirname
=
'./model_path'
,
feeded_var_names
=[
image
.
name
],
target_vars
=[
out
],
main_program
=
val_prog
,
executor
=
exe
,
model_filename
=
'__model__'
,
params_filename
=
'__params__'
)
quant_post_static
(
executor
=
exe
,
model_dir
=
'./model_path'
,
quantize_model_path
=
'./save_path'
,
sample_generator
=
val_reader
,
model_filename
=
'__model__'
,
params_filename
=
'__params__'
,
batch_size
=
16
,
batch_nums
=
10
)
更详细的用法请参考
`
离线量化
demo
<
https
://
github
.
com
/
PaddlePaddle
/
PaddleSlim
/
tree
/
develop
/
demo
/
quant
/
quant_post
>`
_
。
更详细的用法请参考
`
离线量化
demo
<
https
://
github
.
com
/
PaddlePaddle
/
PaddleSlim
/
tree
/
develop
/
demo
/
quant
/
quant_post
>`
_
。
...
@@ -269,11 +307,10 @@ convert
...
@@ -269,11 +307,10 @@ convert
..
code
-
block
::
python
..
code
-
block
::
python
#
encoding
=
utf8
#
encoding
=
utf8
import paddle
import
paddle
.
fluid
as
fluid
import
paddle
.
fluid
as
fluid
import
paddleslim
.
quant
as
quant
import
paddleslim
.
quant
as
quant
paddle.enable_static()
train_program
=
fluid
.
Program
()
train_program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
train_program
):
with
fluid
.
program_guard
(
train_program
):
...
@@ -402,7 +439,7 @@ fluid.Program
...
@@ -402,7 +439,7 @@ fluid.Program
**
代码示例
**
**
代码示例
**
..
code
-
block
::
python
..
code
-
block
::
python
import
paddle
import
paddle
import
paddle
.
fluid
as
fluid
import
paddle
.
fluid
as
fluid
import
paddleslim
.
quant
as
quant
import
paddleslim
.
quant
as
quant
...
...
docs/zh_cn/tutorials/quant/static/quant_post_tutorial.md
浏览文件 @
3a9ed427
...
@@ -17,15 +17,38 @@
...
@@ -17,15 +17,38 @@
主要代码实现如下:
主要代码实现如下:
```
python
```
python
import
paddleslim
import
paddle
model_dir
=
path
/
to
/
fp32_model_params
import
paddle.fluid
as
fluid
save_model_dir
=
path
/
to
/
save_model_path
import
paddle.dataset.mnist
as
reader
paddleslim
.
quant
.
quant_post_dynamic
(
model_dir
=
model_dir
,
from
paddleslim.models
import
MobileNet
save_model_dir
=
save_model_dir
,
from
paddleslim.quant
import
quant_post_dynamic
weight_bits
=
8
,
quantizable_op_type
=
[
'conv2d'
,
'mul'
],
paddle
.
enable_static
()
weight_quantize_type
=
"channel_wise_abs_max"
,
image
=
paddle
.
static
.
data
(
name
=
'image'
,
shape
=
[
None
,
1
,
28
,
28
],
dtype
=
'float32'
)
generate_test_model
=
False
)
model
=
MobileNet
()
out
=
model
.
net
(
input
=
image
,
class_dim
=
10
)
main_prog
=
paddle
.
static
.
default_main_program
()
val_prog
=
main_prog
.
clone
(
for_test
=
True
)
place
=
paddle
.
CUDAPlace
(
0
)
if
paddle
.
is_compiled_with_cuda
()
else
paddle
.
CPUPlace
()
exe
=
paddle
.
static
.
Executor
(
place
)
exe
.
run
(
paddle
.
static
.
default_startup_program
())
paddle
.
fluid
.
io
.
save_inference_model
(
dirname
=
'./model_path'
,
feeded_var_names
=
[
image
.
name
],
target_vars
=
[
out
],
main_program
=
val_prog
,
executor
=
exe
,
model_filename
=
'__model__'
,
params_filename
=
'__params__'
)
quant_post_dynamic
(
model_dir
=
'./model_path'
,
save_model_dir
=
'./save_path'
,
model_filename
=
'__model__'
,
params_filename
=
'__params__'
,
save_model_filename
=
'__model__'
,
save_params_filename
=
'__params__'
)
```
```
## 静态离线量化
## 静态离线量化
...
@@ -47,16 +70,44 @@ paddleslim.quant.quant_post_dynamic(model_dir=model_dir,
...
@@ -47,16 +70,44 @@ paddleslim.quant.quant_post_dynamic(model_dir=model_dir,
主要代码实现如下:
主要代码实现如下:
```
python
```
python
import
paddleslim
import
paddle
import
paddle.fluid
as
fluid
import
paddle.dataset.mnist
as
reader
from
paddleslim.models
import
MobileNet
from
paddleslim.quant
import
quant_post_static
paddle
.
enable_static
()
val_reader
=
reader
.
test
()
use_gpu
=
True
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
paddle
.
enable_static
()
image
=
paddle
.
static
.
data
(
name
=
'image'
,
shape
=
[
None
,
1
,
28
,
28
],
dtype
=
'float32'
)
model
=
MobileNet
()
out
=
model
.
net
(
input
=
image
,
class_dim
=
10
)
main_prog
=
paddle
.
static
.
default_main_program
()
val_prog
=
main_prog
.
clone
(
for_test
=
True
)
place
=
paddle
.
CUDAPlace
(
0
)
if
paddle
.
is_compiled_with_cuda
()
else
paddle
.
CPUPlace
()
exe
=
paddle
.
static
.
Executor
(
place
)
exe
=
paddle
.
static
.
Executor
(
place
)
paddleslim
.
quant
.
quant_post
(
exe
.
run
(
paddle
.
static
.
default_startup_program
())
executor
=
exe
,
model_dir
=
model_path
,
paddle
.
fluid
.
io
.
save_inference_model
(
quantize_model_path
=
save_path
,
dirname
=
'./model_path'
,
sample_generator
=
reader
,
feeded_var_names
=
[
image
.
name
],
model_filename
=
model_filename
,
target_vars
=
[
out
],
params_filename
=
params_filename
,
main_program
=
val_prog
,
batch_nums
=
batch_num
)
executor
=
exe
,
model_filename
=
'__model__'
,
params_filename
=
'__params__'
)
quant_post_static
(
executor
=
exe
,
model_dir
=
'./model_path'
,
quantize_model_path
=
'./save_path'
,
sample_generator
=
val_reader
,
model_filename
=
'__model__'
,
params_filename
=
'__params__'
,
batch_size
=
16
,
batch_nums
=
10
)
```
```
详细代码与例程请参考:
[
静态离线量化
](
https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/quant/quant_post
)
详细代码与例程请参考:
[
静态离线量化
](
https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/quant/quant_post
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录