Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
4b014a1b
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4b014a1b
编写于
5月 14, 2022
作者:
W
weishengyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dbg
上级
45f2d010
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
18 deletion
+45
-18
ppcls/configs/StrategySearch/person.yaml
ppcls/configs/StrategySearch/person.yaml
+5
-2
ppcls/configs/cls_demo/person/Distillation/PPLCNet_x1_0_distillation.yaml
...s_demo/person/Distillation/PPLCNet_x1_0_distillation.yaml
+0
-1
tools/search_strategy.py
tools/search_strategy.py
+40
-15
未找到文件。
ppcls/configs/StrategySearch/person.yaml
浏览文件 @
4b014a1b
...
@@ -23,13 +23,16 @@ search_dict:
...
@@ -23,13 +23,16 @@ search_dict:
search_values
:
[
0.0
,
0.1
,
0.5
]
search_values
:
[
0.0
,
0.1
,
0.5
]
lr_mult_list
:
lr_mult_list
:
replace_config
:
replace_config
:
-
Arch.
models.1.Student.
lr_mult_list
-
Arch.lr_mult_list
search_values
:
search_values
:
-
[
0.0
,
0.2
,
0.4
,
0.6
,
0.8
,
1.0
]
-
[
0.0
,
0.2
,
0.4
,
0.6
,
0.8
,
1.0
]
-
[
0.0
,
0.4
,
0.4
,
0.8
,
0.8
,
1.0
]
-
[
0.0
,
0.4
,
0.4
,
0.8
,
0.8
,
1.0
]
teacher
:
teacher
:
rm_keys
:
rm_keys
:
-
Arch.
models.1.Student.
lr_mult_list
-
Arch.lr_mult_list
search_values
:
search_values
:
-
ResNet101_vd
-
ResNet101_vd
-
ResNet50_vd
-
ResNet50_vd
final_replace
:
Arch.lr_mult_list
:
Arch.models.1.Student.lr_mult_list
ppcls/configs/cls_demo/person/Distillation/PPLCNet_x1_0_distillation.yaml
浏览文件 @
4b014a1b
...
@@ -33,7 +33,6 @@ Arch:
...
@@ -33,7 +33,6 @@ Arch:
-
Teacher
:
-
Teacher
:
name
:
ResNet101_vd
name
:
ResNet101_vd
class_num
:
*class_num
class_num
:
*class_num
pretrained
:
"
./output/TEACHER_ResNet101_vd/ResNet101_vd/best_model"
-
Student
:
-
Student
:
name
:
PPLCNet_x1_0
name
:
PPLCNet_x1_0
class_num
:
*class_num
class_num
:
*class_num
...
...
tools/search_strategy.py
浏览文件 @
4b014a1b
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
os
import
sys
__dir__
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
sys
.
path
.
append
(
os
.
path
.
abspath
(
os
.
path
.
join
(
__dir__
,
'../'
)))
import
subprocess
import
subprocess
from
ppcls.utils
import
config
from
ppcls.utils
import
config
...
@@ -6,11 +14,11 @@ def get_result(log_dir):
...
@@ -6,11 +14,11 @@ def get_result(log_dir):
log_file
=
"{}/train.log"
.
format
(
log_dir
)
log_file
=
"{}/train.log"
.
format
(
log_dir
)
with
open
(
log_file
,
"r"
)
as
f
:
with
open
(
log_file
,
"r"
)
as
f
:
raw
=
f
.
read
()
raw
=
f
.
read
()
res
=
float
(
raw
.
split
(
"best metric "
)[
-
1
].
split
(
"]"
)[
0
])
res
=
float
(
raw
.
split
(
"best metric
:
"
)[
-
1
].
split
(
"]"
)[
0
])
return
res
return
res
def
search_train
(
search_list
,
base_program
,
base_output_dir
,
search_key
,
config_replace_value
):
def
search_train
(
search_list
,
base_program
,
base_output_dir
,
search_key
,
config_replace_value
,
model_name
):
best_res
=
0.
best_res
=
0.
best
=
search_list
[
0
]
best
=
search_list
[
0
]
all_result
=
{}
all_result
=
{}
...
@@ -18,11 +26,14 @@ def search_train(search_list, base_program, base_output_dir, search_key, config_
...
@@ -18,11 +26,14 @@ def search_train(search_list, base_program, base_output_dir, search_key, config_
program
=
base_program
.
copy
()
program
=
base_program
.
copy
()
for
v
in
config_replace_value
:
for
v
in
config_replace_value
:
program
+=
[
"-o"
,
"{}={}"
.
format
(
v
,
search_i
)]
program
+=
[
"-o"
,
"{}={}"
.
format
(
v
,
search_i
)]
output_dir
=
"{}/{}_{}"
.
format
(
base_output_dir
,
search_key
,
search_i
.
replace
(
"."
,
"_"
))
if
v
==
"Arch.name"
:
model_name
=
search_i
output_dir
=
"{}/{}_{}"
.
format
(
base_output_dir
,
search_key
,
search_i
).
replace
(
"."
,
"_"
)
program
+=
[
"-o"
,
"Global.output_dir={}"
.
format
(
output_dir
)]
program
+=
[
"-o"
,
"Global.output_dir={}"
.
format
(
output_dir
)]
subprocess
.
Popen
(
program
)
process
=
subprocess
.
Popen
(
program
)
res
=
get_result
(
output_dir
)
process
.
communicate
()
all_result
[
search_i
]
=
res
res
=
get_result
(
"{}/{}"
.
format
(
output_dir
,
model_name
))
all_result
[
str
(
search_i
)]
=
res
if
res
>
best_res
:
if
res
>
best_res
:
best
=
search_i
best
=
search_i
best_res
=
res
best_res
=
res
...
@@ -34,16 +45,19 @@ def search_strategy():
...
@@ -34,16 +45,19 @@ def search_strategy():
args
=
config
.
parse_args
()
args
=
config
.
parse_args
()
configs
=
config
.
get_config
(
args
.
config
,
overrides
=
args
.
override
,
show
=
False
)
configs
=
config
.
get_config
(
args
.
config
,
overrides
=
args
.
override
,
show
=
False
)
base_config_file
=
configs
[
"base_config_file"
]
base_config_file
=
configs
[
"base_config_file"
]
distill_config_file
=
configs
[
"distill_config_file"
]
model_name
=
config
.
get_config
(
base_config_file
)[
"Arch"
][
"name"
]
gpus
=
configs
[
"gpus"
]
gpus
=
configs
[
"gpus"
]
gpus
=
","
.
join
([
str
(
i
)
for
i
in
gpus
])
base_program
=
[
"python3.7"
,
"-m"
,
"paddle.distributed.launch"
,
"--gpus={}"
.
format
(
gpus
),
base_program
=
[
"python3.7"
,
"-m"
,
"paddle.distributed.launch"
,
"--gpus={}"
.
format
(
gpus
),
"tools/train.py"
,
"-c"
,
base_config_file
]
"tools/train.py"
,
"-c"
,
base_config_file
]
base_output_dir
=
configs
[
"output_dir"
]
base_output_dir
=
configs
[
"output_dir"
]
search_dict
=
configs
.
get
(
"search_dict"
)
search_dict
=
configs
.
get
(
"search_dict"
)
all_results
=
{}
all_results
=
{}
for
search_key
in
search_dict
:
for
search_key
in
search_dict
:
search_values
=
configs
[
search_key
][
"search_values"
]
search_values
=
search_dict
[
search_key
][
"search_values"
]
replace_config
=
search_dict
[
search_key
][
"replace_config"
]
replace_config
=
search_dict
[
search_key
][
"replace_config"
]
res
=
search_train
(
search_values
,
base_program
,
base_output_dir
,
search_key
,
replace_config
)
res
=
search_train
(
search_values
,
base_program
,
base_output_dir
,
search_key
,
replace_config
,
model_name
)
all_results
[
search_key
]
=
res
all_results
[
search_key
]
=
res
best
=
res
.
get
(
"best"
)
best
=
res
.
get
(
"best"
)
for
v
in
replace_config
:
for
v
in
replace_config
:
...
@@ -56,22 +70,33 @@ def search_strategy():
...
@@ -56,22 +70,33 @@ def search_strategy():
teacher_rm_keys
=
teacher_configs
[
"rm_keys"
]
teacher_rm_keys
=
teacher_configs
[
"rm_keys"
]
rm_indices
=
[]
rm_indices
=
[]
for
rm_k
in
teacher_rm_keys
:
for
rm_k
in
teacher_rm_keys
:
rm_indices
.
append
(
base_program
.
index
(
rm_k
))
for
ind
,
ki
in
enumerate
(
base_program
):
rm_indices
=
sorted
(
rm_indices
)
if
rm_k
in
ki
:
for
rm_index
in
rm_indices
[:,
:,
-
1
]:
rm_indices
.
append
(
ind
)
teacher_program
.
pop
(
rm_index
+
1
)
print
(
rm_indices
)
for
rm_index
in
rm_indices
[::
-
1
]:
teacher_program
.
pop
(
rm_index
)
teacher_program
.
pop
(
rm_index
)
replace_config
=
"-o Arch.name"
teacher_program
.
pop
(
rm_index
-
1
)
replace_config
=
[
"Arch.name"
]
teacher_list
=
teacher_configs
[
"search_values"
]
teacher_list
=
teacher_configs
[
"search_values"
]
res
=
search_train
(
teacher_list
,
teacher_program
,
base_output_dir
,
"teacher"
,
replace_config
)
res
=
search_train
(
teacher_list
,
teacher_program
,
base_output_dir
,
"teacher"
,
replace_config
,
model_name
)
all_results
[
"teacher"
]
=
res
all_results
[
"teacher"
]
=
res
best
=
res
.
get
(
"best"
)
best
=
res
.
get
(
"best"
)
t_pretrained
=
"{}/{}_{}
"
.
format
(
base_output_dir
,
"teacher"
,
best
.
replace
(
"."
,
"_"
)
)
t_pretrained
=
"{}/{}_{}
/{}/best_model"
.
format
(
base_output_dir
,
"teacher"
,
best
,
best
)
base_program
+=
[
"-o"
,
"Arch.models.0.Teacher.name={}"
.
format
(
best
),
base_program
+=
[
"-o"
,
"Arch.models.0.Teacher.name={}"
.
format
(
best
),
"-o"
,
"Arch.models.0.Teacher.pretrained={}"
.
format
(
t_pretrained
)]
"-o"
,
"Arch.models.0.Teacher.pretrained={}"
.
format
(
t_pretrained
)]
output_dir
=
"{}/search_res"
.
format
(
base_output_dir
)
output_dir
=
"{}/search_res"
.
format
(
base_output_dir
)
base_program
+=
[
"-o"
,
"Global.output_dir={}"
.
format
(
output_dir
)]
base_program
+=
[
"-o"
,
"Global.output_dir={}"
.
format
(
output_dir
)]
final_replace
=
configs
.
get
(
'final_replace'
)
for
i
in
range
(
len
(
base_program
)):
base_program
[
i
]
=
base_program
[
i
].
replace
(
base_config_file
,
distill_config_file
)
for
k
in
final_replace
:
v
=
final_replace
[
k
]
base_program
[
i
]
=
base_program
[
i
].
replace
(
k
,
v
)
subprocess
.
Popen
(
base_program
)
subprocess
.
Popen
(
base_program
)
subprocess
.
communicate
()
print
(
all_results
,
base_program
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录