Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
42eb23d3
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看板
未验证
提交
42eb23d3
编写于
12月 15, 2020
作者:
B
Bai Yifan
提交者:
GitHub
12月 15, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix dygraph quant demo issues (#543)
上级
cd94b6b7
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
51 addition
and
15 deletion
+51
-15
demo/dygraph/quant/README.md
demo/dygraph/quant/README.md
+1
-1
demo/dygraph/quant/train.py
demo/dygraph/quant/train.py
+50
-14
未找到文件。
demo/dygraph/quant/README.md
浏览文件 @
42eb23d3
...
...
@@ -82,7 +82,7 @@ quanter.save_quantized_model(net, 'save_dir', input_spec=[paddle.static.InputSpe
# 单卡训练
python train.py
--lr
=
0.001
--use_pact
=
True
--num_epochs
=
30
--l2_decay
=
2e-5
--ls_epsilon
=
0.1
# 多卡训练,以0到3号卡为例
python
-m
paddle.distributed.launch
--gpus
=
"0,1,2,3"
train.py
--lr
=
0.001
--use_pact
=
True
--num_epochs
=
6
0
--l2_decay
=
2e-5
--ls_epsilon
=
0.1
python
-m
paddle.distributed.launch
--gpus
=
"0,1,2,3"
train.py
--lr
=
0.001
--use_pact
=
True
--num_epochs
=
3
0
--l2_decay
=
2e-5
--ls_epsilon
=
0.1
```
...
...
demo/dygraph/quant/train.py
浏览文件 @
42eb23d3
...
...
@@ -43,7 +43,7 @@ _logger = get_logger(__name__, level=logging.INFO)
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
add_arg
=
functools
.
partial
(
add_arguments
,
argparser
=
parser
)
# yapf: disable
add_arg
(
'batch_size'
,
int
,
256
,
"Minibatch size."
)
add_arg
(
'batch_size'
,
int
,
256
,
"
Single Card
Minibatch size."
)
add_arg
(
'use_gpu'
,
bool
,
True
,
"Whether to use GPU or not."
)
add_arg
(
'model'
,
str
,
"mobilenet_v3"
,
"The target model."
)
add_arg
(
'pretrained_model'
,
str
,
"MobileNetV3_large_x1_0_ssld_pretrained"
,
"Whether to use pretrained model."
)
...
...
@@ -57,7 +57,7 @@ add_arg('num_epochs', int, 1,
add_arg
(
'total_images'
,
int
,
1281167
,
"The number of total training images."
)
add_arg
(
'data'
,
str
,
"imagenet"
,
"Which data to use. 'mnist' or 'imagenet'"
)
add_arg
(
'log_period'
,
int
,
10
,
"Log period in batches."
)
add_arg
(
'model_save_dir'
,
str
,
"./
"
,
"model save directory."
)
add_arg
(
'model_save_dir'
,
str
,
"./
output_models"
,
"model save directory."
)
parser
.
add_argument
(
'--step_epochs'
,
nargs
=
'+'
,
type
=
int
,
default
=
[
10
,
20
,
30
],
help
=
"piecewise decay step"
)
# yapf: enable
...
...
@@ -110,12 +110,12 @@ def compress(args):
if
use_data_parallel
:
paddle
.
distributed
.
init_parallel_env
()
if
args
.
model
==
"mobilenet_v1"
:
pretrain
=
True
if
args
.
data
==
"imagenet"
else
False
net
=
mobilenet_v1
(
pretrained
=
pretrained
)
if
args
.
model
==
"mobilenet_v1"
:
net
=
mobilenet_v1
(
pretrained
=
pretrain
)
elif
args
.
model
==
"mobilenet_v3"
:
net
=
MobileNetV3_large_x1_0
()
if
args
.
data
==
"imagenet"
:
if
pretrain
:
load_dygraph_pretrain
(
net
,
args
.
pretrained_model
,
True
)
else
:
raise
ValueError
(
"{} is not supported."
.
format
(
args
.
model
))
...
...
@@ -190,25 +190,43 @@ def compress(args):
batch_id
=
0
acc_top1_ns
=
[]
acc_top5_ns
=
[]
eval_reader_cost
=
0.0
eval_run_cost
=
0.0
total_samples
=
0
reader_start
=
time
.
time
()
for
data
in
valid_loader
():
eval_reader_cost
+=
time
.
time
()
-
reader_start
image
=
data
[
0
]
label
=
data
[
1
]
start_time
=
time
.
time
()
eval_start
=
time
.
time
()
out
=
net
(
image
)
acc_top1
=
paddle
.
metric
.
accuracy
(
input
=
out
,
label
=
label
,
k
=
1
)
acc_top5
=
paddle
.
metric
.
accuracy
(
input
=
out
,
label
=
label
,
k
=
5
)
end_time
=
time
.
time
()
eval_run_cost
+=
time
.
time
()
-
eval_start
batch_size
=
image
.
shape
[
0
]
total_samples
+=
batch_size
if
batch_id
%
args
.
log_period
==
0
:
log_period
=
1
if
batch_id
==
0
else
args
.
log_period
_logger
.
info
(
"Eval epoch[{}] batch[{}] -
acc_top1: {:.6f}; acc_top5: {:.6f}; time: {:.3f}
"
.
"Eval epoch[{}] batch[{}] -
top1: {:.6f}; top5: {:.6f}; avg_reader_cost: {:.6f} s, avg_batch_cost: {:.6f} s, avg_samples: {}, avg_ips: {:.3f} images/s
"
.
format
(
epoch
,
batch_id
,
np
.
mean
(
acc_top1
.
numpy
()),
np
.
mean
(
acc_top5
.
numpy
()),
end_time
-
start_time
))
np
.
mean
(
acc_top5
.
numpy
()),
eval_reader_cost
/
log_period
,
(
eval_reader_cost
+
eval_run_cost
)
/
log_period
,
total_samples
/
log_period
,
total_samples
/
(
eval_reader_cost
+
eval_run_cost
)))
eval_reader_cost
=
0.0
eval_run_cost
=
0.0
total_samples
=
0
acc_top1_ns
.
append
(
np
.
mean
(
acc_top1
.
numpy
()))
acc_top5_ns
.
append
(
np
.
mean
(
acc_top5
.
numpy
()))
batch_id
+=
1
reader_start
=
time
.
time
()
_logger
.
info
(
"Final eval epoch[{}] - acc_top1: {:.6f}; acc_top5: {:.6f}"
.
format
(
...
...
@@ -234,11 +252,18 @@ def compress(args):
net
.
train
()
batch_id
=
0
train_reader_cost
=
0.0
train_run_cost
=
0.0
total_samples
=
0
reader_start
=
time
.
time
()
for
data
in
train_loader
():
train_reader_cost
+=
time
.
time
()
-
reader_start
image
=
data
[
0
]
label
=
data
[
1
]
start_time
=
time
.
time
()
train_start
=
time
.
time
()
out
=
net
(
image
)
avg_cost
=
cross_entropy
(
out
,
label
,
args
.
ls_epsilon
)
...
...
@@ -253,14 +278,25 @@ def compress(args):
acc_top1_n
=
np
.
mean
(
acc_top1
.
numpy
())
acc_top5_n
=
np
.
mean
(
acc_top5
.
numpy
())
end_time
=
time
.
time
()
train_run_cost
+=
time
.
time
()
-
train_start
batch_size
=
image
.
shape
[
0
]
total_samples
+=
batch_size
if
batch_id
%
args
.
log_period
==
0
:
log_period
=
1
if
batch_id
==
0
else
args
.
log_period
_logger
.
info
(
"epoch[{}]-batch[{}] lr: {:.6f} - loss: {:.6f};
acc_top1: {:.6f}; acc_top5: {:.6f}; time: {:.3f}
"
.
"epoch[{}]-batch[{}] lr: {:.6f} - loss: {:.6f};
top1: {:.6f}; top5: {:.6f}; avg_reader_cost: {:.6f} s, avg_batch_cost: {:.6f} s, avg_samples: {}, avg_ips: {:.3f} images/s
"
.
format
(
epoch
,
batch_id
,
lr
.
get_lr
(),
loss_n
,
acc_top1_n
,
acc_top5_n
,
end_time
-
start_time
))
lr
.
get_lr
(),
loss_n
,
acc_top1_n
,
acc_top5_n
,
train_reader_cost
/
log_period
,
(
train_reader_cost
+
train_run_cost
)
/
log_period
,
total_samples
/
log_period
,
total_samples
/
(
train_reader_cost
+
train_run_cost
)))
train_reader_cost
=
0.0
train_run_cost
=
0.0
total_samples
=
0
batch_id
+=
1
reader_start
=
time
.
time
()
############################################################################################################
# train loop
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录