Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
def286ba
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看板
未验证
提交
def286ba
编写于
6月 07, 2022
作者:
littletomatodonkey
提交者:
GitHub
6月 07, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add support for no dist (#1989)
上级
787f91b6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
51 addition
and
23 deletion
+51
-23
docs/zh_CN/PULC/PULC_traffic_sign.md
docs/zh_CN/PULC/PULC_traffic_sign.md
+1
-1
ppcls/configs/PULC/traffic_sign/search.yaml
ppcls/configs/PULC/traffic_sign/search.yaml
+1
-0
ppcls/configs/PULC/vehicle_attr/search.yaml
ppcls/configs/PULC/vehicle_attr/search.yaml
+1
-0
ppcls/data/preprocess/ops/operators.py
ppcls/data/preprocess/ops/operators.py
+0
-3
tools/search_strategy.py
tools/search_strategy.py
+48
-19
未找到文件。
docs/zh_CN/PULC/PULC_traffic_sign.md
浏览文件 @
def286ba
...
...
@@ -131,7 +131,7 @@ cd path_to_PaddleClas
```
shell
cd
dataset
wget https://paddleclas.bj.bcebos.com/data/
cls_demo
/traffic_sign.tar
wget https://paddleclas.bj.bcebos.com/data/
PULC
/traffic_sign.tar
tar
-xf
traffic_sign.tar
cd
../
```
...
...
ppcls/configs/PULC/traffic_sign/search.yaml
浏览文件 @
def286ba
...
...
@@ -30,6 +30,7 @@ search_dict:
-
[
0.0
,
0.4
,
0.4
,
0.8
,
0.8
,
1.0
]
-
[
1.0
,
1.0
,
1.0
,
1.0
,
1.0
,
1.0
]
teacher
:
algorithm
:
"
skl-ugi"
rm_keys
:
-
Arch.lr_mult_list
search_values
:
...
...
ppcls/configs/PULC/vehicle_attr/search.yaml
浏览文件 @
def286ba
...
...
@@ -25,6 +25,7 @@ search_dict:
-
[
0.0
,
0.4
,
0.4
,
0.8
,
0.8
,
1.0
]
-
[
1.0
,
1.0
,
1.0
,
1.0
,
1.0
,
1.0
]
teacher
:
algorithm
:
"
skl-ugi"
rm_keys
:
-
Arch.lr_mult_list
search_values
:
...
...
ppcls/data/preprocess/ops/operators.py
浏览文件 @
def286ba
...
...
@@ -365,9 +365,6 @@ class RandomCropImage(object):
j
=
random
.
randint
(
0
,
w
-
tw
)
img
=
img
[
i
:
i
+
th
,
j
:
j
+
tw
,
:]
if
img
.
shape
[
0
]
!=
256
or
img
.
shape
[
1
]
!=
192
:
raise
ValueError
(
'sample: '
,
h
,
w
,
i
,
j
,
th
,
tw
,
img
.
shape
)
return
img
...
...
tools/search_strategy.py
浏览文件 @
def286ba
...
...
@@ -20,8 +20,13 @@ def get_result(log_dir):
return
res
def
search_train
(
search_list
,
base_program
,
base_output_dir
,
search_key
,
config_replace_value
,
model_name
,
search_times
=
1
):
def
search_train
(
search_list
,
base_program
,
base_output_dir
,
search_key
,
config_replace_value
,
model_name
,
search_times
=
1
):
best_res
=
0.
best
=
search_list
[
0
]
all_result
=
{}
...
...
@@ -33,7 +38,8 @@ def search_train(search_list, base_program, base_output_dir, search_key,
model_name
=
search_i
res_list
=
[]
for
j
in
range
(
search_times
):
output_dir
=
"{}/{}_{}_{}"
.
format
(
base_output_dir
,
search_key
,
search_i
,
j
).
replace
(
"."
,
"_"
)
output_dir
=
"{}/{}_{}_{}"
.
format
(
base_output_dir
,
search_key
,
search_i
,
j
).
replace
(
"."
,
"_"
)
program
+=
[
"-o"
,
"Global.output_dir={}"
.
format
(
output_dir
)]
process
=
subprocess
.
Popen
(
program
)
process
.
communicate
()
...
...
@@ -50,14 +56,17 @@ def search_train(search_list, base_program, base_output_dir, search_key,
def
search_strategy
():
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"
]
distill_config_file
=
configs
[
"distill_config_file"
]
model_name
=
config
.
get_config
(
base_config_file
)[
"Arch"
][
"name"
]
gpus
=
configs
[
"gpus"
]
gpus
=
","
.
join
([
str
(
i
)
for
i
in
gpus
])
base_program
=
[
"python3.7"
,
"-m"
,
"paddle.distributed.launch"
,
"--gpus={}"
.
format
(
gpus
),
"tools/train.py"
,
"-c"
,
base_config_file
]
base_program
=
[
"python3.7"
,
"-m"
,
"paddle.distributed.launch"
,
"--gpus={}"
.
format
(
gpus
),
"tools/train.py"
,
"-c"
,
base_config_file
]
base_output_dir
=
configs
[
"output_dir"
]
search_times
=
configs
[
"search_times"
]
search_dict
=
configs
.
get
(
"search_dict"
)
...
...
@@ -67,41 +76,61 @@ def search_strategy():
search_values
=
search_i
[
"search_values"
]
replace_config
=
search_i
[
"replace_config"
]
res
=
search_train
(
search_values
,
base_program
,
base_output_dir
,
search_key
,
replace_config
,
model_name
,
search_times
)
search_key
,
replace_config
,
model_name
,
search_times
)
all_results
[
search_key
]
=
res
best
=
res
.
get
(
"best"
)
for
v
in
replace_config
:
base_program
+=
[
"-o"
,
"{}={}"
.
format
(
v
,
best
)]
teacher_configs
=
configs
.
get
(
"teacher"
,
None
)
if
teacher_configs
is
not
None
:
if
teacher_configs
is
None
:
print
(
all_results
,
base_program
)
return
algo
=
teacher_configs
.
get
(
"algorithm"
,
"skl-ugi"
)
supported_list
=
[
"skl-ugi"
,
"udml"
]
assert
algo
in
supported_list
,
f
"algorithm must be in
{
supported_list
}
but got
{
algo
}
"
if
algo
==
"skl-ugi"
:
teacher_program
=
base_program
.
copy
()
# remove incompatible keys
teacher_rm_keys
=
teacher_configs
[
"rm_keys"
]
rm_indices
=
[]
for
rm_k
in
teacher_rm_keys
:
for
ind
,
ki
in
enumerate
(
base_program
):
if
rm_k
in
ki
:
rm_indices
.
append
(
ind
)
if
rm_k
in
ki
:
rm_indices
.
append
(
ind
)
for
rm_index
in
rm_indices
[::
-
1
]:
teacher_program
.
pop
(
rm_index
)
teacher_program
.
pop
(
rm_index
-
1
)
teacher_program
.
pop
(
rm_index
-
1
)
replace_config
=
[
"Arch.name"
]
teacher_list
=
teacher_configs
[
"search_values"
]
res
=
search_train
(
teacher_list
,
teacher_program
,
base_output_dir
,
"teacher"
,
replace_config
,
model_name
)
res
=
search_train
(
teacher_list
,
teacher_program
,
base_output_dir
,
"teacher"
,
replace_config
,
model_name
)
all_results
[
"teacher"
]
=
res
best
=
res
.
get
(
"best"
)
t_pretrained
=
"{}/{}_{}_0/{}/best_model"
.
format
(
base_output_dir
,
"teacher"
,
best
,
best
)
base_program
+=
[
"-o"
,
"Arch.models.0.Teacher.name={}"
.
format
(
best
),
"-o"
,
"Arch.models.0.Teacher.pretrained={}"
.
format
(
t_pretrained
)]
t_pretrained
=
"{}/{}_{}_0/{}/best_model"
.
format
(
base_output_dir
,
"teacher"
,
best
,
best
)
base_program
+=
[
"-o"
,
"Arch.models.0.Teacher.name={}"
.
format
(
best
),
"-o"
,
"Arch.models.0.Teacher.pretrained={}"
.
format
(
t_pretrained
)
]
elif
algo
==
"udml"
:
if
"lr_mult_list"
in
all_results
:
base_program
+=
[
"-o"
,
"Arch.models.0.Teacher.lr_mult_list={}"
.
format
(
all_results
[
"lr_mult_list"
][
"best"
])
]
output_dir
=
"{}/search_res"
.
format
(
base_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
)
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
)
process
=
subprocess
.
Popen
(
base_program
)
process
.
communicate
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录