Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleGAN
提交
516213ac
P
PaddleGAN
项目概览
PaddlePaddle
/
PaddleGAN
1 年多 前同步成功
通知
97
Star
7254
Fork
1210
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleGAN
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
516213ac
编写于
2月 02, 2023
作者:
W
wangna11BD
提交者:
GitHub
2月 02, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TIPC-Benchmark]Support @to_static traing for Benchmark for cyclegan (#739)
上级
9a9670da
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
58 addition
and
13 deletion
+58
-13
configs/cyclegan_horse2zebra.yaml
configs/cyclegan_horse2zebra.yaml
+2
-0
ppgan/models/__init__.py
ppgan/models/__init__.py
+1
-1
ppgan/models/base_model.py
ppgan/models/base_model.py
+14
-0
ppgan/models/cycle_gan_model.py
ppgan/models/cycle_gan_model.py
+10
-2
test_tipc/benchmark_train.sh
test_tipc/benchmark_train.sh
+18
-5
test_tipc/configs/CycleGAN/train_infer_python.txt
test_tipc/configs/CycleGAN/train_infer_python.txt
+1
-1
test_tipc/test_train_inference_python.sh
test_tipc/test_train_inference_python.sh
+12
-4
未找到文件。
configs/cyclegan_horse2zebra.yaml
浏览文件 @
516213ac
...
...
@@ -26,6 +26,8 @@ model:
gan_criterion
:
name
:
GANLoss
gan_mode
:
lsgan
# training model under @to_static
to_static
:
False
export_model
:
-
{
name
:
'
netG_A'
,
inputs_num
:
1
}
...
...
ppgan/models/__init__.py
浏览文件 @
516213ac
...
...
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
.base_model
import
BaseModel
from
.base_model
import
BaseModel
,
apply_to_static
from
.gan_model
import
GANModel
from
.cycle_gan_model
import
CycleGANModel
from
.pix2pix_model
import
Pix2PixModel
...
...
ppgan/models/base_model.py
浏览文件 @
516213ac
...
...
@@ -19,9 +19,13 @@ import numpy as np
from
collections
import
OrderedDict
from
abc
import
ABC
,
abstractmethod
from
paddle.jit
import
to_static
from
paddle.static
import
InputSpec
from
.criterions.builder
import
build_criterion
from
..solver
import
build_lr_scheduler
,
build_optimizer
from
..utils.visual
import
tensor2img
from
..utils.logger
import
get_logger
class
BaseModel
(
ABC
):
...
...
@@ -217,3 +221,13 @@ class BaseModel(ABC):
model_name
),
model_filename
=
"{}.pdmodel"
.
format
(
model_name
),
params_filename
=
"{}.pdiparams"
.
format
(
model_name
))
def
apply_to_static
(
support_to_static
,
image_shape
,
model
):
if
support_to_static
:
specs
=
None
if
image_shape
is
not
None
:
specs
=
[
InputSpec
([
None
]
+
image_shape
)]
model
=
to_static
(
model
,
input_spec
=
specs
)
logger
=
get_logger
(
'ppgan'
)
logger
.
info
(
"Successfully to apply @to_static with specs: {}"
.
format
(
specs
))
return
model
\ No newline at end of file
ppgan/models/cycle_gan_model.py
浏览文件 @
516213ac
...
...
@@ -13,7 +13,7 @@
# limitations under the License.
import
paddle
from
.base_model
import
BaseModel
from
.base_model
import
BaseModel
,
apply_to_static
from
.builder
import
MODELS
from
.generators.builder
import
build_generator
...
...
@@ -40,7 +40,9 @@ class CycleGANModel(BaseModel):
pool_size
=
50
,
direction
=
'a2b'
,
lambda_a
=
10.
,
lambda_b
=
10.
):
lambda_b
=
10.
,
to_static
=
False
,
image_shape
=
None
):
"""Initialize the CycleGAN class.
Args:
...
...
@@ -59,6 +61,9 @@ class CycleGANModel(BaseModel):
# Code (vs. paper): G_A (G), G_B (F), D_A (D_Y), D_B (D_X)
self
.
nets
[
'netG_A'
]
=
build_generator
(
generator
)
self
.
nets
[
'netG_B'
]
=
build_generator
(
generator
)
# set @to_static for benchmark, skip this by default.
apply_to_static
(
to_static
,
image_shape
,
self
.
nets
[
'netG_A'
])
apply_to_static
(
to_static
,
image_shape
,
self
.
nets
[
'netG_B'
])
init_weights
(
self
.
nets
[
'netG_A'
])
init_weights
(
self
.
nets
[
'netG_B'
])
...
...
@@ -66,6 +71,9 @@ class CycleGANModel(BaseModel):
if
discriminator
:
self
.
nets
[
'netD_A'
]
=
build_discriminator
(
discriminator
)
self
.
nets
[
'netD_B'
]
=
build_discriminator
(
discriminator
)
# set @to_static for benchmark, skip this by default.
apply_to_static
(
to_static
,
image_shape
,
self
.
nets
[
'netD_A'
])
apply_to_static
(
to_static
,
image_shape
,
self
.
nets
[
'netD_B'
])
init_weights
(
self
.
nets
[
'netD_A'
])
init_weights
(
self
.
nets
[
'netD_B'
])
...
...
test_tipc/benchmark_train.sh
浏览文件 @
516213ac
...
...
@@ -67,6 +67,19 @@ FILENAME=$new_filename
# MODE must be one of ['benchmark_train']
MODE
=
$2
PARAMS
=
$3
REST_ARGS
=
$4
to_static
=
"d2sF"
# parse "to_static" options and modify trainer into "to_static_trainer"
if
[
$REST_ARGS
=
"to_static"
]
||
[
$PARAMS
=
"to_static"
]
;
then
to_static
=
"d2sT"
sed
-i
's/trainer:norm_train/trainer:to_static_train/g'
$FILENAME
# clear PARAM contents
if
[
$PARAMS
=
"to_static"
]
;
then
PARAMS
=
""
fi
fi
IFS
=
$'
\n
'
# parser params from train_benchmark.txt
dataline
=
`
cat
$FILENAME
`
...
...
@@ -161,7 +174,7 @@ for batch_size in ${batch_size_list[*]}; do
if
[
${#
gpu_id
}
-le
1
]
;
then
log_path
=
"
$SAVE_LOG
/profiling_log"
mkdir
-p
$log_path
log_name
=
"
${
repo_name
}
_
${
model_name
}
_bs
${
batch_size
}
_
${
precision
}
_
${
run_mode
}
_
${
device_num
}
_profiling"
log_name
=
"
${
repo_name
}
_
${
model_name
}
_bs
${
batch_size
}
_
${
precision
}
_
${
run_mode
}
_
${
device_num
}
_
${
to_static
}
_
profiling"
func_sed_params
"
$FILENAME
"
"
${
line_gpuid
}
"
"0"
# sed used gpu_id
# set profile_option params
tmp
=
`
sed
-i
"
${
line_profile
}
s/.*/
${
profile_option
}
/"
"
${
FILENAME
}
"
`
...
...
@@ -177,8 +190,8 @@ for batch_size in ${batch_size_list[*]}; do
speed_log_path
=
"
$SAVE_LOG
/index"
mkdir
-p
$log_path
mkdir
-p
$speed_log_path
log_name
=
"
${
repo_name
}
_
${
model_name
}
_bs
${
batch_size
}
_
${
precision
}
_
${
run_mode
}
_
${
device_num
}
_log"
speed_log_name
=
"
${
repo_name
}
_
${
model_name
}
_bs
${
batch_size
}
_
${
precision
}
_
${
run_mode
}
_
${
device_num
}
_speed"
log_name
=
"
${
repo_name
}
_
${
model_name
}
_bs
${
batch_size
}
_
${
precision
}
_
${
run_mode
}
_
${
device_num
}
_
${
to_static
}
_
log"
speed_log_name
=
"
${
repo_name
}
_
${
model_name
}
_bs
${
batch_size
}
_
${
precision
}
_
${
run_mode
}
_
${
device_num
}
_
${
to_static
}
_
speed"
func_sed_params
"
$FILENAME
"
"
${
line_profile
}
"
"null"
# sed profile_id as null
cmd
=
"bash test_tipc/test_train_inference_python.sh
${
FILENAME
}
benchmark_train >
${
log_path
}
/
${
log_name
}
2>&1 "
echo
$cmd
...
...
@@ -212,8 +225,8 @@ for batch_size in ${batch_size_list[*]}; do
speed_log_path
=
"
$SAVE_LOG
/index"
mkdir
-p
$log_path
mkdir
-p
$speed_log_path
log_name
=
"
${
repo_name
}
_
${
model_name
}
_bs
${
batch_size
}
_
${
precision
}
_
${
run_mode
}
_
${
device_num
}
_log"
speed_log_name
=
"
${
repo_name
}
_
${
model_name
}
_bs
${
batch_size
}
_
${
precision
}
_
${
run_mode
}
_
${
device_num
}
_speed"
log_name
=
"
${
repo_name
}
_
${
model_name
}
_bs
${
batch_size
}
_
${
precision
}
_
${
run_mode
}
_
${
device_num
}
_
${
to_static
}
_
log"
speed_log_name
=
"
${
repo_name
}
_
${
model_name
}
_bs
${
batch_size
}
_
${
precision
}
_
${
run_mode
}
_
${
device_num
}
_
${
to_static
}
_
speed"
func_sed_params
"
$FILENAME
"
"
${
line_gpuid
}
"
"
$gpu_id
"
# sed used gpu_id
func_sed_params
"
$FILENAME
"
"
${
line_profile
}
"
"null"
# sed --profile_option as null
cmd
=
"bash test_tipc/test_train_inference_python.sh
${
FILENAME
}
benchmark_train >
${
log_path
}
/
${
log_name
}
2>&1 "
...
...
test_tipc/configs/CycleGAN/train_infer_python.txt
浏览文件 @
516213ac
...
...
@@ -17,7 +17,7 @@ norm_train:tools/main.py -c configs/cyclegan_horse2zebra.yaml --seed 123 -o log_
pact_train:null
fpgm_train:null
distill_train:null
null:null
to_static_train:-o model.to_static=True
null:null
##
===========================eval_params===========================
...
...
test_tipc/test_train_inference_python.sh
浏览文件 @
516213ac
...
...
@@ -33,8 +33,8 @@ trainer_list=$(func_parser_value "${lines[14]}")
trainer_norm
=
$(
func_parser_key
"
${
lines
[15]
}
"
)
norm_trainer
=
$(
func_parser_value
"
${
lines
[15]
}
"
)
t
rainer_key1
=
$(
func_parser_key
"
${
lines
[19]
}
"
)
t
rainer_value1
=
$(
func_parser_value
"
${
lines
[19]
}
"
)
t
o_static_key
=
$(
func_parser_key
"
${
lines
[19]
}
"
)
t
o_static_trainer
=
$(
func_parser_value
"
${
lines
[19]
}
"
)
trainer_key2
=
$(
func_parser_key
"
${
lines
[20]
}
"
)
trainer_value2
=
$(
func_parser_value
"
${
lines
[20]
}
"
)
...
...
@@ -218,8 +218,16 @@ else
fi
for
trainer
in
${
trainer_list
[*]
}
;
do
flag_quant
=
False
run_train
=
${
norm_trainer
}
run_export
=
${
norm_export
}
# In case of @to_static, we re-used norm_traier,
# but append "-o Global.to_static=True" for config
# to trigger "apply_to_static" logic in 'engine.py'
if
[
${
trainer
}
=
"
${
to_static_key
}
"
]
;
then
run_train
=
"
${
norm_trainer
}
${
to_static_trainer
}
"
run_export
=
${
norm_export
}
else
run_train
=
${
norm_trainer
}
run_export
=
${
norm_export
}
fi
if
[
${
run_train
}
=
"null"
]
;
then
continue
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录