Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
d1e78e57
M
models
项目概览
PaddlePaddle
/
models
接近 2 年 前同步成功
通知
230
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看板
未验证
提交
d1e78e57
编写于
9月 25, 2018
作者:
W
whs
提交者:
GitHub
9月 25, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change the loss of c_gan and dc_gan. (#1283)
* Change the loss of c_gan and dc_gan. * Remove unused comment.
上级
ff60ed86
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
9 deletion
+19
-9
fluid/gan/c_gan/c_gan.py
fluid/gan/c_gan/c_gan.py
+7
-2
fluid/gan/c_gan/dc_gan.py
fluid/gan/c_gan/dc_gan.py
+12
-7
未找到文件。
fluid/gan/c_gan/c_gan.py
浏览文件 @
d1e78e57
...
@@ -40,7 +40,9 @@ add_arg('use_gpu', bool, True, "Whether to use GPU to train.")
...
@@ -40,7 +40,9 @@ add_arg('use_gpu', bool, True, "Whether to use GPU to train.")
def
loss
(
x
,
label
):
def
loss
(
x
,
label
):
return
fluid
.
layers
.
mean
(
x
*
(
label
-
0.5
))
return
fluid
.
layers
.
mean
(
fluid
.
layers
.
sigmoid_cross_entropy_with_logits
(
x
=
x
,
label
=
label
))
def
train
(
args
):
def
train
(
args
):
...
@@ -67,7 +69,10 @@ def train(args):
...
@@ -67,7 +69,10 @@ def train(args):
g_program_test
=
dg_program
.
clone
(
for_test
=
True
)
g_program_test
=
dg_program
.
clone
(
for_test
=
True
)
dg_logit
=
D_cond
(
g_img
,
conditions
)
dg_logit
=
D_cond
(
g_img
,
conditions
)
dg_loss
=
loss
(
dg_logit
,
1
)
dg_loss
=
loss
(
dg_logit
,
fluid
.
layers
.
fill_constant_batch_size_like
(
input
=
noise
,
dtype
=
'float32'
,
shape
=
[
-
1
,
1
],
value
=
1.0
))
opt
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
LEARNING_RATE
)
opt
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
LEARNING_RATE
)
...
...
fluid/gan/c_gan/dc_gan.py
浏览文件 @
d1e78e57
...
@@ -32,15 +32,17 @@ LEARNING_RATE = 2e-4
...
@@ -32,15 +32,17 @@ LEARNING_RATE = 2e-4
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
add_arg
=
functools
.
partial
(
add_arguments
,
argparser
=
parser
)
add_arg
=
functools
.
partial
(
add_arguments
,
argparser
=
parser
)
# yapf: disable
# yapf: disable
add_arg
(
'batch_size'
,
int
,
12
1
,
"Minibatch size."
)
add_arg
(
'batch_size'
,
int
,
12
8
,
"Minibatch size."
)
add_arg
(
'epoch'
,
int
,
20
,
"The number of epoched to be trained."
)
add_arg
(
'epoch'
,
int
,
20
,
"The number of epoched to be trained."
)
add_arg
(
'output'
,
str
,
"./output"
,
"The directory the model and the test result to be saved to."
)
add_arg
(
'output'
,
str
,
"./output
_dcgan
"
,
"The directory the model and the test result to be saved to."
)
add_arg
(
'use_gpu'
,
bool
,
True
,
"Whether to use GPU to train."
)
add_arg
(
'use_gpu'
,
bool
,
True
,
"Whether to use GPU to train."
)
# yapf: enable
# yapf: enable
def
loss
(
x
,
label
):
def
loss
(
x
,
label
):
return
fluid
.
layers
.
mean
(
x
*
(
label
-
0.5
))
return
fluid
.
layers
.
mean
(
fluid
.
layers
.
sigmoid_cross_entropy_with_logits
(
x
=
x
,
label
=
label
))
def
train
(
args
):
def
train
(
args
):
...
@@ -63,7 +65,10 @@ def train(args):
...
@@ -63,7 +65,10 @@ def train(args):
g_program_test
=
dg_program
.
clone
(
for_test
=
True
)
g_program_test
=
dg_program
.
clone
(
for_test
=
True
)
dg_logit
=
D
(
g_img
)
dg_logit
=
D
(
g_img
)
dg_loss
=
loss
(
dg_logit
,
1
)
dg_loss
=
loss
(
dg_logit
,
fluid
.
layers
.
fill_constant_batch_size_like
(
input
=
noise
,
dtype
=
'float32'
,
shape
=
[
-
1
,
1
],
value
=
1.0
))
opt
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
LEARNING_RATE
)
opt
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
LEARNING_RATE
)
...
@@ -139,9 +144,9 @@ def train(args):
...
@@ -139,9 +144,9 @@ def train(args):
fetch_list
=
{
g_img
})[
0
]
fetch_list
=
{
g_img
})[
0
]
total_images
=
np
.
concatenate
([
real_image
,
generated_images
])
total_images
=
np
.
concatenate
([
real_image
,
generated_images
])
fig
=
plot
(
total_images
)
fig
=
plot
(
total_images
)
msg
=
"Epoch ID={0}
\n
Batch ID={1}
\n
D-Loss={2}
\n
DG-Loss={3}
\n
gen={4}"
.
format
(
msg
=
"Epoch ID={0}
Batch ID={1} D-Loss={2}
DG-Loss={3}
\n
gen={4}"
.
format
(
pass_id
,
batch_id
,
d_loss_np
,
dg_loss_np
,
pass_id
,
batch_id
,
check
(
generated_images
))
np
.
sum
(
d_loss_np
),
dg_loss_np
,
check
(
generated_images
))
print
(
msg
)
print
(
msg
)
plt
.
title
(
msg
)
plt
.
title
(
msg
)
plt
.
savefig
(
plt
.
savefig
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录