Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
a45431c9
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看板
未验证
提交
a45431c9
编写于
8月 10, 2020
作者:
B
Bai Yifan
提交者:
GitHub
8月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support pact demo load checkpoints (#414)
上级
7c8ba912
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
9 deletion
+27
-9
demo/quant/pact_quant_aware/README.md
demo/quant/pact_quant_aware/README.md
+2
-2
demo/quant/pact_quant_aware/train.py
demo/quant/pact_quant_aware/train.py
+25
-7
未找到文件。
demo/quant/pact_quant_aware/README.md
浏览文件 @
a45431c9
...
...
@@ -159,7 +159,7 @@ compiled_train_prog = compiled_train_prog.with_data_parallel(
普通量化:
```
python train.py --model MobileNetV3_large_x1_0 --pretrained_model ./pretrain/MobileNetV3_large_x1_0_ssld_pretrained --
checkpoint_dir ./output/MobileNetV3_large_x1_0 --
num_epochs 30 --lr 0.0001 --use_pact False
python train.py --model MobileNetV3_large_x1_0 --pretrained_model ./pretrain/MobileNetV3_large_x1_0_ssld_pretrained --num_epochs 30 --lr 0.0001 --use_pact False
```
...
...
@@ -179,7 +179,7 @@ python train.py --model MobileNetV3_large_x1_0 --pretrained_model ./pretrain/Mob
使用PACT量化训练
```
python train.py --model MobileNetV3_large_x1_0 --pretrained_model ./pretrain/MobileNetV3_large_x1_0_ssld_pretrained --
checkpoint_dir ./output/MobileNetV3_large_x1_0 --
num_epochs 30 --lr 0.0001 --use_pact True --batch_size 128 --lr_strategy=piecewise_decay --step_epochs 20 --l2_decay 1e-5
python train.py --model MobileNetV3_large_x1_0 --pretrained_model ./pretrain/MobileNetV3_large_x1_0_ssld_pretrained --num_epochs 30 --lr 0.0001 --use_pact True --batch_size 128 --lr_strategy=piecewise_decay --step_epochs 20 --l2_decay 1e-5
```
输出结果为
...
...
demo/quant/pact_quant_aware/train.py
浏览文件 @
a45431c9
...
...
@@ -53,8 +53,12 @@ add_arg('data', str, "imagenet",
"Which data to use. 'mnist' or 'imagenet'"
)
add_arg
(
'log_period'
,
int
,
10
,
"Log period in batches."
)
add_arg
(
'checkpoint_dir'
,
str
,
"output"
,
"checkpoint save dir"
)
add_arg
(
'checkpoint_dir'
,
str
,
None
,
"checkpoint dir"
)
add_arg
(
'checkpoint_epoch'
,
int
,
None
,
"checkpoint epoch"
)
add_arg
(
'output_dir'
,
str
,
"output/MobileNetV3_large_x1_0"
,
"model save dir"
)
add_arg
(
'use_pact'
,
bool
,
True
,
"Whether to use PACT or not."
)
...
...
@@ -244,6 +248,7 @@ def compress(args):
compiled_train_prog
,
feed
=
train_feeder
.
feed
(
data
),
fetch_list
=
[
avg_cost
.
name
,
acc_top1
.
name
,
acc_top5
.
name
])
end_time
=
time
.
time
()
loss_n
=
np
.
mean
(
loss_n
)
acc_top1_n
=
np
.
mean
(
acc_top1_n
)
...
...
@@ -279,24 +284,37 @@ def compress(args):
# train loop
best_acc1
=
0.0
best_epoch
=
0
for
i
in
range
(
args
.
num_epochs
):
start_epoch
=
0
if
args
.
checkpoint_dir
is
not
None
:
ckpt_path
=
args
.
checkpoint_dir
assert
args
.
checkpoint_epoch
is
not
None
,
"checkpoint_epoch must be set"
start_epoch
=
args
.
checkpoint_epoch
fluid
.
io
.
load_persistables
(
exe
,
dirname
=
args
.
checkpoint_dir
,
main_program
=
val_program
)
start_step
=
start_epoch
*
int
(
math
.
ceil
(
float
(
args
.
total_images
)
/
args
.
batch_size
))
v
=
fluid
.
global_scope
().
find_var
(
'@LR_DECAY_COUNTER@'
).
get_tensor
()
v
.
set
(
np
.
array
([
start_step
]).
astype
(
np
.
float32
),
place
)
for
i
in
range
(
start_epoch
,
args
.
num_epochs
):
train
(
i
,
compiled_train_prog
)
acc1
=
test
(
i
,
val_program
)
fluid
.
io
.
save_persistables
(
exe
,
dirname
=
os
.
path
.
join
(
args
.
checkpoin
t_dir
,
str
(
i
)),
dirname
=
os
.
path
.
join
(
args
.
outpu
t_dir
,
str
(
i
)),
main_program
=
val_program
)
if
acc1
>
best_acc1
:
best_acc1
=
acc1
best_epoch
=
i
fluid
.
io
.
save_persistables
(
exe
,
dirname
=
os
.
path
.
join
(
args
.
checkpoin
t_dir
,
'best_model'
),
dirname
=
os
.
path
.
join
(
args
.
outpu
t_dir
,
'best_model'
),
main_program
=
val_program
)
if
os
.
path
.
exists
(
os
.
path
.
join
(
args
.
checkpoin
t_dir
,
'best_model'
)):
if
os
.
path
.
exists
(
os
.
path
.
join
(
args
.
outpu
t_dir
,
'best_model'
)):
fluid
.
io
.
load_persistables
(
exe
,
dirname
=
os
.
path
.
join
(
args
.
checkpoin
t_dir
,
'best_model'
),
dirname
=
os
.
path
.
join
(
args
.
outpu
t_dir
,
'best_model'
),
main_program
=
val_program
)
# 3. Freeze the graph after training by adjusting the quantize
# operators' order for the inference.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录