Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
5b717b1b
M
models
项目概览
PaddlePaddle
/
models
1 年多 前同步成功
通知
222
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看板
未验证
提交
5b717b1b
编写于
9月 03, 2019
作者:
Z
Zhen Wang
提交者:
GitHub
9月 03, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change for quant demo in lite tutorial. (#3250)
上级
8ed8df0b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
9 deletion
+20
-9
PaddleSlim/compress.py
PaddleSlim/compress.py
+16
-6
PaddleSlim/configs/quantization.yaml
PaddleSlim/configs/quantization.yaml
+2
-2
PaddleSlim/run.sh
PaddleSlim/run.sh
+2
-1
未找到文件。
PaddleSlim/compress.py
浏览文件 @
5b717b1b
...
...
@@ -24,13 +24,15 @@ add_arg = functools.partial(add_arguments, argparser=parser)
# yapf: disable
add_arg
(
'batch_size'
,
int
,
64
*
4
,
"Minibatch size."
)
add_arg
(
'use_gpu'
,
bool
,
True
,
"Whether to use GPU or not."
)
add_arg
(
'total_images'
,
int
,
1281167
,
"Training image number."
)
add_arg
(
'class_dim'
,
int
,
1000
,
"Class number."
)
add_arg
(
'image_shape'
,
str
,
"3,224,224"
,
"Input image size"
)
add_arg
(
'model'
,
str
,
"MobileNet"
,
"Set the network to use."
)
add_arg
(
'model'
,
str
,
"MobileNet"
,
"Set the network to use."
)
add_arg
(
'pretrained_model'
,
str
,
None
,
"Whether to use pretrained model."
)
add_arg
(
'teacher_model'
,
str
,
None
,
"Set the teacher network to use."
)
add_arg
(
'teacher_model'
,
str
,
None
,
"Set the teacher network to use."
)
add_arg
(
'teacher_pretrained_model'
,
str
,
None
,
"Whether to use pretrained model."
)
add_arg
(
'compress_config'
,
str
,
None
,
"The config file for compression with yaml format."
)
add_arg
(
'compress_config'
,
str
,
None
,
"The config file for compression with yaml format."
)
add_arg
(
'quant_only'
,
bool
,
False
,
"Only do quantization-aware training."
)
# yapf: enable
model_list
=
[
m
for
m
in
dir
(
models
)
if
"__"
not
in
m
]
...
...
@@ -64,12 +66,20 @@ def compress(args):
acc_top1
=
fluid
.
layers
.
accuracy
(
input
=
out
,
label
=
label
,
k
=
1
)
acc_top5
=
fluid
.
layers
.
accuracy
(
input
=
out
,
label
=
label
,
k
=
5
)
val_program
=
fluid
.
default_main_program
().
clone
()
if
args
.
quant_only
:
boundaries
=
[
args
.
total_images
/
args
.
batch_size
*
10
,
args
.
total_images
/
args
.
batch_size
*
16
]
values
=
[
1e-4
,
1e-5
,
1e-6
]
else
:
boundaries
=
[
args
.
total_images
/
args
.
batch_size
*
30
,
args
.
total_images
/
args
.
batch_size
*
60
,
args
.
total_images
/
args
.
batch_size
*
90
]
values
=
[
0.1
,
0.01
,
0.001
,
0.0001
]
opt
=
fluid
.
optimizer
.
Momentum
(
momentum
=
0.9
,
learning_rate
=
fluid
.
layers
.
piecewise_decay
(
boundaries
=
[
5000
*
30
,
5000
*
60
,
5000
*
90
]
,
values
=
[
0.1
,
0.01
,
0.001
,
0.0001
]
),
boundaries
=
boundaries
,
values
=
values
),
regularization
=
fluid
.
regularizer
.
L2Decay
(
4e-5
))
place
=
fluid
.
CUDAPlace
(
0
)
if
args
.
use_gpu
else
fluid
.
CPUPlace
()
...
...
PaddleSlim/configs/quantization.yaml
浏览文件 @
5b717b1b
...
...
@@ -3,7 +3,7 @@ strategies:
quantization_strategy
:
class
:
'
QuantizationStrategy'
start_epoch
:
0
end_epoch
:
20
end_epoch
:
19
float_model_save_path
:
'
./output/float'
mobile_model_save_path
:
'
./output/mobile'
int8_model_save_path
:
'
./output/int8'
...
...
@@ -14,7 +14,7 @@ strategies:
save_in_nodes
:
[
'
image'
]
save_out_nodes
:
[
'
fc_0.tmp_2'
]
compressor
:
epoch
:
2
1
epoch
:
2
0
checkpoint_path
:
'
./checkpoints_quan/'
strategies
:
-
quantization_strategy
PaddleSlim/run.sh
浏览文件 @
5b717b1b
...
...
@@ -82,7 +82,8 @@ cd -
#--batch_size 64 \
#--model "MobileNet" \
#--pretrained_model ./pretrain/MobileNetV1_pretrained \
#--compress_config ./configs/quantization.yaml
#--compress_config ./configs/quantization.yaml \
#--quant_only True
# for distillation with quantization
#-----------------------------------
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录