Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
862d459d
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看板
提交
862d459d
编写于
1月 10, 2020
作者:
u010070587
提交者:
kolinwei
1月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add PaddleGAN models (#4184)
上级
4d33a3f0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
111 addition
and
13 deletion
+111
-13
PaddleCV/PaddleGAN/trainer/AttGAN.py
PaddleCV/PaddleGAN/trainer/AttGAN.py
+38
-5
PaddleCV/PaddleGAN/trainer/STGAN.py
PaddleCV/PaddleGAN/trainer/STGAN.py
+41
-6
PaddleCV/PaddleGAN/trainer/StarGAN.py
PaddleCV/PaddleGAN/trainer/StarGAN.py
+32
-2
未找到文件。
PaddleCV/PaddleGAN/trainer/AttGAN.py
浏览文件 @
862d459d
...
...
@@ -156,8 +156,13 @@ class DTrainer():
def
gradient_penalty
(
self
,
f
,
real
,
fake
=
None
,
cfg
=
None
,
name
=
None
):
def
_interpolate
(
a
,
b
=
None
):
if
b
is
None
:
beta
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
a
.
shape
,
min
=
0.0
,
max
=
1.0
)
if
cfg
.
enable_ce
:
beta
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
a
.
shape
,
min
=
0.0
,
max
=
1.0
,
seed
=
1
)
else
:
beta
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
a
.
shape
,
min
=
0.0
,
max
=
1.0
)
mean
=
fluid
.
layers
.
reduce_mean
(
a
,
dim
=
list
(
range
(
len
(
a
.
shape
))),
keep_dim
=
True
)
input_sub_mean
=
fluid
.
layers
.
elementwise_sub
(
a
,
mean
,
axis
=
0
)
...
...
@@ -167,8 +172,13 @@ class DTrainer():
keep_dim
=
True
)
b
=
beta
*
fluid
.
layers
.
sqrt
(
var
)
*
0.5
+
a
shape
=
[
a
.
shape
[
0
]]
alpha
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
shape
,
min
=
0.0
,
max
=
1.0
)
if
cfg
.
enable_ce
:
alpha
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
shape
,
min
=
0.0
,
max
=
1.0
,
seed
=
1
)
else
:
alpha
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
shape
,
min
=
0.0
,
max
=
1.0
)
inner
=
fluid
.
layers
.
elementwise_mul
((
b
-
a
),
alpha
,
axis
=
0
)
+
a
return
inner
...
...
@@ -254,6 +264,10 @@ class AttGAN(object):
default
=
None
,
help
=
"the normalization in discriminator, choose in [None, instance_norm]"
)
parser
.
add_argument
(
'--enable_ce'
,
action
=
'store_true'
,
help
=
"if set, run the tasks with continuous evaluation logs"
)
return
parser
...
...
@@ -282,6 +296,9 @@ class AttGAN(object):
name
=
'label_org_'
,
shape
=
[
None
,
self
.
cfg
.
c_dim
],
dtype
=
'float32'
)
label_trg_
=
fluid
.
data
(
name
=
'label_trg_'
,
shape
=
[
None
,
self
.
cfg
.
c_dim
],
dtype
=
'float32'
)
# used for continuous evaluation
if
self
.
cfg
.
enable_ce
:
fluid
.
default_startup_program
().
random_seed
=
90
py_reader
=
fluid
.
io
.
PyReader
(
feed_list
=
[
image_real
,
label_org
,
label_trg
],
...
...
@@ -325,7 +342,11 @@ class AttGAN(object):
dis_trainer
.
program
).
with_data_parallel
(
loss_name
=
dis_trainer
.
d_loss
.
name
,
build_strategy
=
build_strategy
)
# used for continuous evaluation
if
self
.
cfg
.
enable_ce
:
gen_trainer_program
.
random_seed
=
90
dis_trainer_program
.
random_seed
=
90
t_time
=
0
for
epoch_id
in
range
(
self
.
cfg
.
epoch
):
...
...
@@ -367,6 +388,8 @@ class AttGAN(object):
d_loss_gp
[
0
],
batch_time
))
sys
.
stdout
.
flush
()
batch_id
+=
1
if
self
.
cfg
.
enable_ce
and
batch_id
==
100
:
break
if
self
.
cfg
.
run_test
:
image_name
=
fluid
.
data
(
...
...
@@ -393,3 +416,13 @@ class AttGAN(object):
"net_G"
)
utility
.
checkpoints
(
epoch_id
,
self
.
cfg
,
exe
,
dis_trainer
,
"net_D"
)
# used for continuous evaluation
if
self
.
cfg
.
enable_ce
:
device_num
=
fluid
.
core
.
get_cuda_device_count
()
if
self
.
cfg
.
use_gpu
else
1
print
(
"kpis
\t
attgan_g_loss_fake_card{}
\t
{}"
.
format
(
device_num
,
g_loss_fake
[
0
]))
print
(
"kpis
\t
attgan_g_loss_rec_card{}
\t
{}"
.
format
(
device_num
,
g_loss_rec
[
0
]))
print
(
"kpis
\t
attgan_g_loss_cls_card{}
\t
{}"
.
format
(
device_num
,
g_loss_cls
[
0
]))
print
(
"kpis
\t
attgan_d_loss_real_card{}
\t
{}"
.
format
(
device_num
,
d_loss_real
[
0
]))
print
(
"kpis
\t
attgan_d_loss_fake_card{}
\t
{}"
.
format
(
device_num
,
d_loss_fake
[
0
]))
print
(
"kpis
\t
attgan_d_loss_gp_card{}
\t
{}"
.
format
(
device_num
,
d_loss_gp
[
0
]))
print
(
"kpis
\t
attgan_Batch_time_cost_card{}
\t
{}"
.
format
(
device_num
,
batch_time
))
PaddleCV/PaddleGAN/trainer/STGAN.py
浏览文件 @
862d459d
...
...
@@ -164,8 +164,13 @@ class DTrainer():
def
gradient_penalty
(
self
,
f
,
real
,
fake
=
None
,
cfg
=
None
,
name
=
None
):
def
_interpolate
(
a
,
b
=
None
):
if
b
is
None
:
beta
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
a
.
shape
,
min
=
0.0
,
max
=
1.0
)
if
cfg
.
enable_ce
:
beta
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
a
.
shape
,
min
=
0.0
,
max
=
1.0
,
seed
=
1
)
else
:
beta
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
a
.
shape
,
min
=
0.0
,
max
=
1.0
)
mean
=
fluid
.
layers
.
reduce_mean
(
a
,
dim
=
list
(
range
(
len
(
a
.
shape
))),
keep_dim
=
True
)
input_sub_mean
=
fluid
.
layers
.
elementwise_sub
(
a
,
mean
,
axis
=
0
)
...
...
@@ -175,8 +180,13 @@ class DTrainer():
keep_dim
=
True
)
b
=
beta
*
fluid
.
layers
.
sqrt
(
var
)
*
0.5
+
a
shape
=
[
a
.
shape
[
0
]]
alpha
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
shape
,
min
=
0.0
,
max
=
1.0
)
if
cfg
.
enable_ce
:
alpha
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
shape
,
min
=
0.0
,
max
=
1.0
,
seed
=
1
)
else
:
alpha
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
shape
,
min
=
0.0
,
max
=
1.0
)
inner
=
fluid
.
layers
.
elementwise_mul
((
b
-
a
),
alpha
,
axis
=
0
)
+
a
return
inner
...
...
@@ -269,7 +279,10 @@ class STGAN(object):
default
=
None
,
help
=
"the normalization in discriminator, choose in [None, instance_norm]"
)
parser
.
add_argument
(
'--enable_ce'
,
action
=
'store_true'
,
help
=
"if set, run the tasks with continuous evaluation logs"
)
return
parser
def
__init__
(
self
,
...
...
@@ -296,6 +309,9 @@ class STGAN(object):
name
=
'label_org_'
,
shape
=
[
None
,
self
.
cfg
.
c_dim
],
dtype
=
'float32'
)
label_trg_
=
fluid
.
data
(
name
=
'label_trg_'
,
shape
=
[
None
,
self
.
cfg
.
c_dim
],
dtype
=
'float32'
)
# used for continuous evaluation
if
self
.
cfg
.
enable_ce
:
fluid
.
default_startup_program
().
random_seed
=
90
test_gen_trainer
=
GTrainer
(
image_real
,
label_org
,
label_org_
,
label_trg
,
label_trg_
,
self
.
cfg
,
...
...
@@ -339,7 +355,11 @@ class STGAN(object):
dis_trainer
.
program
).
with_data_parallel
(
loss_name
=
dis_trainer
.
d_loss
.
name
,
build_strategy
=
build_strategy
)
# used for continuous evaluation
if
self
.
cfg
.
enable_ce
:
gen_trainer_program
.
random_seed
=
90
dis_trainer_program
.
random_seed
=
90
t_time
=
0
total_train_batch
=
0
# used for benchmark
...
...
@@ -382,6 +402,9 @@ class STGAN(object):
d_loss_gp
[
0
],
batch_time
))
sys
.
stdout
.
flush
()
batch_id
+=
1
if
self
.
cfg
.
enable_ce
and
batch_id
==
100
:
break
total_train_batch
+=
1
# used for benchmark
# profiler tools
if
self
.
cfg
.
profile
and
epoch_id
==
0
and
batch_id
==
self
.
cfg
.
print_freq
:
...
...
@@ -413,3 +436,15 @@ class STGAN(object):
"net_G"
)
utility
.
checkpoints
(
epoch_id
,
self
.
cfg
,
exe
,
dis_trainer
,
"net_D"
)
# used for continuous evaluation
if
self
.
cfg
.
enable_ce
:
device_num
=
fluid
.
core
.
get_cuda_device_count
()
if
self
.
cfg
.
use_gpu
else
1
print
(
"kpis
\t
stgan_g_loss_fake_card{}
\t
{}"
.
format
(
device_num
,
g_loss_fake
[
0
]))
print
(
"kpis
\t
stgan_g_loss_rec_card{}
\t
{}"
.
format
(
device_num
,
g_loss_rec
[
0
]))
print
(
"kpis
\t
stgan_g_loss_cls_card{}
\t
{}"
.
format
(
device_num
,
g_loss_cls
[
0
]))
print
(
"kpis
\t
stgan_d_loss_card{}
\t
{}"
.
format
(
device_num
,
d_loss
[
0
]))
print
(
"kpis
\t
stgan_d_loss_real_card{}
\t
{}"
.
format
(
device_num
,
d_loss_real
[
0
]))
print
(
"kpis
\t
stgan_d_loss_fake_card{}
\t
{}"
.
format
(
device_num
,
d_loss_fake
[
0
]))
print
(
"kpis
\t
stgan_d_loss_cls_card{}
\t
{}"
.
format
(
device_num
,
d_loss_cls
[
0
]))
print
(
"kpis
\t
stgan_d_loss_gp_card{}
\t
{}"
.
format
(
device_num
,
d_loss_gp
[
0
]))
print
(
"kpis
\t
stgan_Batch_time_cost_card{}
\t
{}"
.
format
(
device_num
,
batch_time
))
PaddleCV/PaddleGAN/trainer/StarGAN.py
浏览文件 @
862d459d
...
...
@@ -159,8 +159,12 @@ class DTrainer():
def
gradient_penalty
(
self
,
f
,
real
,
fake
,
cfg
=
None
,
name
=
None
):
def
_interpolate
(
a
,
b
):
shape
=
[
a
.
shape
[
0
]]
alpha
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
shape
,
min
=
0.0
,
max
=
1.0
)
if
cfg
.
enable_ce
:
alpha
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
shape
,
min
=
0.0
,
max
=
1.0
,
seed
=
1
)
else
:
alpha
=
fluid
.
layers
.
uniform_random_batch_size_like
(
input
=
a
,
shape
=
shape
,
min
=
0.0
,
max
=
1.0
)
inner
=
fluid
.
layers
.
elementwise_mul
(
b
,
(
1.0
-
alpha
),
axis
=
0
)
+
fluid
.
layers
.
elementwise_mul
(
a
,
alpha
,
axis
=
0
)
return
inner
...
...
@@ -245,6 +249,10 @@ class StarGAN(object):
help
=
"the attributes we selected to change"
)
parser
.
add_argument
(
'--n_samples'
,
type
=
int
,
default
=
1
,
help
=
"batch size when testing"
)
parser
.
add_argument
(
'--enable_ce'
,
action
=
'store_true'
,
help
=
"if set, run the tasks with continuous evaluation logs"
)
return
parser
...
...
@@ -268,6 +276,9 @@ class StarGAN(object):
name
=
'label_org'
,
shape
=
[
None
,
self
.
cfg
.
c_dim
],
dtype
=
'float32'
)
label_trg
=
fluid
.
data
(
name
=
'label_trg'
,
shape
=
[
None
,
self
.
cfg
.
c_dim
],
dtype
=
'float32'
)
# used for continuous evaluation
if
self
.
cfg
.
enable_ce
:
fluid
.
default_startup_program
().
random_seed
=
90
py_reader
=
fluid
.
io
.
PyReader
(
feed_list
=
[
image_real
,
label_org
,
label_trg
],
...
...
@@ -304,6 +315,10 @@ class StarGAN(object):
dis_trainer
.
program
).
with_data_parallel
(
loss_name
=
dis_trainer
.
d_loss
.
name
,
build_strategy
=
build_strategy
)
# used for continuous evaluation
if
self
.
cfg
.
enable_ce
:
gen_trainer_program
.
random_seed
=
90
dis_trainer_program
.
random_seed
=
90
t_time
=
0
total_train_batch
=
0
# used for benchmark
...
...
@@ -347,6 +362,10 @@ class StarGAN(object):
sys
.
stdout
.
flush
()
batch_id
+=
1
# used for ce
if
self
.
cfg
.
enable_ce
and
batch_id
==
100
:
break
total_train_batch
+=
1
# used for benchmark
# profiler tools
if
self
.
cfg
.
profile
and
epoch_id
==
0
and
batch_id
==
self
.
cfg
.
print_freq
:
...
...
@@ -378,3 +397,14 @@ class StarGAN(object):
"net_G"
)
utility
.
checkpoints
(
epoch_id
,
self
.
cfg
,
exe
,
dis_trainer
,
"net_D"
)
# used for continuous evaluation
if
self
.
cfg
.
enable_ce
:
device_num
=
fluid
.
core
.
get_cuda_device_count
()
if
self
.
cfg
.
use_gpu
else
1
print
(
"kpis
\t
stargan_g_loss_fake_card{}
\t
{}"
.
format
(
device_num
,
g_loss_fake
[
0
]))
print
(
"kpis
\t
stargan_g_loss_rec_card{}
\t
{}"
.
format
(
device_num
,
g_loss_rec
[
0
]))
print
(
"kpis
\t
stargan_g_loss_cls_card{}
\t
{}"
.
format
(
device_num
,
g_loss_cls
[
0
]))
print
(
"kpis
\t
stargan_d_loss_real_card{}
\t
{}"
.
format
(
device_num
,
d_loss_real
[
0
]))
print
(
"kpis
\t
stargan_d_loss_fake_card{}
\t
{}"
.
format
(
device_num
,
d_loss_fake
[
0
]))
print
(
"kpis
\t
stargan_d_loss_cls_card{}
\t
{}"
.
format
(
device_num
,
d_loss_cls
[
0
]))
print
(
"kpis
\t
stargan_d_loss_gp_card{}
\t
{}"
.
format
(
device_num
,
d_loss_gp
[
0
]))
print
(
"kpis
\t
stargan_Batch_time_cost_card{}
\t
{}"
.
format
(
device_num
,
batch_time
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录