Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
71b7fa84
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看板
未验证
提交
71b7fa84
编写于
10月 10, 2019
作者:
W
whs
提交者:
GitHub
10月 10, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update arguments used to finetune pruned model. (#3485)
上级
de9eb717
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
87 addition
and
29 deletion
+87
-29
PaddleSlim/classification/pruning/README.md
PaddleSlim/classification/pruning/README.md
+19
-2
PaddleSlim/classification/pruning/compress.py
PaddleSlim/classification/pruning/compress.py
+39
-13
PaddleSlim/classification/pruning/configs/mobilenet_v1.yaml
PaddleSlim/classification/pruning/configs/mobilenet_v1.yaml
+1
-1
PaddleSlim/classification/pruning/configs/mobilenet_v2.yaml
PaddleSlim/classification/pruning/configs/mobilenet_v2.yaml
+1
-1
PaddleSlim/classification/pruning/configs/resnet34.yaml
PaddleSlim/classification/pruning/configs/resnet34.yaml
+2
-2
PaddleSlim/classification/pruning/run.sh
PaddleSlim/classification/pruning/run.sh
+25
-10
未找到文件。
PaddleSlim/classification/pruning/README.md
浏览文件 @
71b7fa84
...
...
@@ -130,7 +130,13 @@ fc10_weights (1280L, 1000L)
|-30%|- |- |- |-|
|-50%|- |- |- |-|
>训练超参:
>训练超参
batch size: 256
lr_strategy: piecewise_decay
step_epochs: 30, 60, 90
num_epochs: 120
l2_decay: 3e-5
lr: 0.1
### MobileNetV2
...
...
@@ -142,6 +148,12 @@ fc10_weights (1280L, 1000L)
|-50%|- |- |- |-|
>训练超参:
batch size: 500
lr_strategy: cosine_decay
num_epochs: 240
l2_decay: 4e-5
lr: 0.1
### ResNet50
...
...
@@ -152,6 +164,11 @@ fc10_weights (1280L, 1000L)
|-30%|- |- |- |-|
|-50%|- |- |- |-|
>训练超参:
>训练超参
batch size: 256
lr_strategy: cosine_decay
num_epochs: 120
l2_decay: 1e-4
lr: 0.1
## FAQ
PaddleSlim/classification/pruning/compress.py
浏览文件 @
71b7fa84
...
...
@@ -4,6 +4,7 @@ import logging
import
paddle
import
argparse
import
functools
import
math
import
paddle.fluid
as
fluid
sys
.
path
.
append
(
".."
)
import
imagenet_reader
as
reader
...
...
@@ -24,12 +25,48 @@ add_arg('batch_size', int, 64*4, "Minibatch size.")
add_arg
(
'use_gpu'
,
bool
,
True
,
"Whether to use GPU or not."
)
add_arg
(
'model'
,
str
,
None
,
"The target model."
)
add_arg
(
'pretrained_model'
,
str
,
None
,
"Whether to use pretrained model."
)
add_arg
(
'config_file'
,
str
,
None
,
"The config file for compression with yaml format."
)
add_arg
(
'lr'
,
float
,
0.1
,
"The learning rate used to fine-tune pruned model."
)
add_arg
(
'lr_strategy'
,
str
,
"piecewise_decay"
,
"The learning rate decay strategy."
)
add_arg
(
'l2_decay'
,
float
,
3e-5
,
"The l2_decay parameter."
)
add_arg
(
'momentum_rate'
,
float
,
0.9
,
"The value of momentum_rate."
)
add_arg
(
'num_epochs'
,
int
,
120
,
"The number of total epochs."
)
add_arg
(
'total_images'
,
int
,
1281167
,
"The number of total training images."
)
parser
.
add_argument
(
'--step_epochs'
,
nargs
=
'+'
,
type
=
int
,
default
=
[
30
,
60
,
90
],
help
=
"piecewise decay step"
)
add_arg
(
'config_file'
,
str
,
None
,
"The config file for compression with yaml format."
)
# yapf: enable
model_list
=
[
m
for
m
in
dir
(
models
)
if
"__"
not
in
m
]
def
piecewise_decay
(
args
):
step
=
int
(
math
.
ceil
(
float
(
args
.
total_images
)
/
args
.
batch_size
))
bd
=
[
step
*
e
for
e
in
args
.
step_epochs
]
lr
=
[
args
.
lr
*
(
0.1
**
i
)
for
i
in
range
(
len
(
bd
)
+
1
)]
learning_rate
=
fluid
.
layers
.
piecewise_decay
(
boundaries
=
bd
,
values
=
lr
)
optimizer
=
fluid
.
optimizer
.
Momentum
(
learning_rate
=
learning_rate
,
momentum
=
args
.
momentum_rate
,
regularization
=
fluid
.
regularizer
.
L2Decay
(
args
.
l2_decay
))
return
optimizer
def
cosine_decay
(
args
):
step
=
int
(
math
.
ceil
(
float
(
args
.
total_images
)
/
args
.
batch_size
))
learning_rate
=
fluid
.
layers
.
cosine_decay
(
learning_rate
=
args
.
lr
,
step_each_epoch
=
step
,
epochs
=
args
.
num_epochs
)
optimizer
=
fluid
.
optimizer
.
Momentum
(
learning_rate
=
learning_rate
,
momentum
=
args
.
momentum_rate
,
regularization
=
fluid
.
regularizer
.
L2Decay
(
args
.
l2_decay
))
return
optimizer
def
create_optimizer
(
args
):
if
args
.
lr_strategy
==
"piecewise_decay"
:
return
piecewise_decay
(
args
)
elif
args
.
lr_strategy
==
"cosine_decay"
:
return
cosine_decay
(
args
)
def
compress
(
args
):
class_dim
=
1000
image_shape
=
"3,224,224"
...
...
@@ -45,25 +82,14 @@ 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
()
# for param in fluid.default_main_program().global_block().all_parameters():
# print param.name, param.shape
# return
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
]),
regularization
=
fluid
.
regularizer
.
L2Decay
(
4e-5
))
opt
=
create_optimizer
(
args
)
place
=
fluid
.
CUDAPlace
(
0
)
if
args
.
use_gpu
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
fluid
.
default_startup_program
())
if
args
.
pretrained_model
:
def
if_exist
(
var
):
return
os
.
path
.
exists
(
os
.
path
.
join
(
args
.
pretrained_model
,
var
.
name
))
fluid
.
io
.
load_vars
(
exe
,
args
.
pretrained_model
,
predicate
=
if_exist
)
val_reader
=
paddle
.
batch
(
reader
.
val
(),
batch_size
=
args
.
batch_size
)
...
...
PaddleSlim/classification/pruning/configs/mobilenet_v1.yaml
浏览文件 @
71b7fa84
...
...
@@ -14,7 +14,7 @@ strategies:
target_ratio
:
0.5
pruned_params
:
'
.*_sep_weights'
compressor
:
epoch
:
3
epoch
:
121
checkpoint_path
:
'
./checkpoints/mobilenet_v1/'
strategies
:
-
uniform_pruning_strategy
PaddleSlim/classification/pruning/configs/mobilenet_v2.yaml
浏览文件 @
71b7fa84
...
...
@@ -16,7 +16,7 @@ strategies:
# pruned_params: '.*linear_weights'
# pruned_params: '.*expand_weights'
compressor
:
epoch
:
2
epoch
:
2
41
checkpoint_path
:
'
./checkpoints/'
strategies
:
-
uniform_pruning_strategy
PaddleSlim/classification/pruning/configs/resnet
50
.yaml
→
PaddleSlim/classification/pruning/configs/resnet
34
.yaml
浏览文件 @
71b7fa84
...
...
@@ -14,7 +14,7 @@ strategies:
target_ratio
:
0.5
pruned_params
:
'
.*branch.*_weights'
compressor
:
epoch
:
4
checkpoint_path
:
'
./checkpoints/resnet
50
/'
epoch
:
121
checkpoint_path
:
'
./checkpoints/resnet
34
/'
strategies
:
-
uniform_pruning_strategy
PaddleSlim/classification/pruning/run.sh
浏览文件 @
71b7fa84
...
...
@@ -6,7 +6,7 @@ export CUDA_VISIBLE_DEVICES=0
root_url
=
"http://paddle-imagenet-models-name.bj.bcebos.com"
MobileNetV1
=
"MobileNetV1_pretrained.tar"
MobileNetV2
=
"MobileNetV2_pretrained.tar"
ResNet
50
=
"ResNet50
_pretrained.tar"
ResNet
34
=
"ResNet34
_pretrained.tar"
pretrain_dir
=
'../pretrain'
if
[
!
-d
${
pretrain_dir
}
]
;
then
...
...
@@ -25,9 +25,9 @@ if [ ! -f ${MobileNetV2} ]; then
tar
xf
${
MobileNetV2
}
fi
if
[
!
-f
${
ResNet
50
}
]
;
then
wget
${
root_url
}
/
${
ResNet
50
}
tar
xf
${
ResNet
50
}
if
[
!
-f
${
ResNet
34
}
]
;
then
wget
${
root_url
}
/
${
ResNet
34
}
tar
xf
${
ResNet
34
}
fi
cd
-
...
...
@@ -36,6 +36,11 @@ nohup python -u compress.py \
--model
"MobileNet"
\
--use_gpu
1
\
--batch_size
256
\
--total_images
1281167
\
--lr_strategy
"piecewise_decay"
\
--num_epochs
120
\
--lr
0.1
\
--l2_decay
3e-5
\
--pretrained_model
../pretrain/MobileNetV1_pretrained
\
--config_file
"./configs/mobilenet_v1.yaml"
\
>
mobilenet_v1.log 2>&1 &
...
...
@@ -46,18 +51,28 @@ tailf mobilenet_v1.log
#--model "MobileNetV2" \
#--use_gpu 1 \
#--batch_size 256 \
#--total_images 1281167 \
#--lr_strategy "cosine_decay" \
#--num_epochs 240 \
#--lr 0.1 \
#--l2_decay 4e-5 \
#--pretrained_model ../pretrain/MobileNetV2_pretrained \
#--config_file "./configs/mobilenet_v2.yaml" \
#> mobilenet_v2.log 2>&1 &
#tailf mobilenet_v2.log
## for compression of resnet
50
## for compression of resnet
34
#python -u compress.py \
#--model "ResNet
50
" \
#--model "ResNet
34
" \
#--use_gpu 1 \
#--batch_size 256 \
#--pretrained_model ../pretrain/ResNet50_pretrained \
#--config_file "./configs/resnet50.yaml" \
#> resnet50.log 2>&1 &
#tailf resnet50.log
#--total_images 1281167 \
#--lr_strategy "cosine_decay" \
#--lr 0.1 \
#--num_epochs 120 \
#--l2_decay 1e-4 \
#--pretrained_model ../pretrain/ResNet34_pretrained \
#--config_file "./configs/resnet34.yaml" \
#> resnet34.log 2>&1 &
#tailf resnet34.log
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录