Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
fcc4581e
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看板
未验证
提交
fcc4581e
编写于
6月 23, 2019
作者:
L
lvmengsi
提交者:
GitHub
6月 23, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix grad as list (#2493)
* fix grad and scipy version
上级
d7541747
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
33 addition
and
29 deletion
+33
-29
PaddleCV/gan/data_reader.py
PaddleCV/gan/data_reader.py
+1
-1
PaddleCV/gan/infer.py
PaddleCV/gan/infer.py
+6
-5
PaddleCV/gan/trainer/AttGAN.py
PaddleCV/gan/trainer/AttGAN.py
+5
-4
PaddleCV/gan/trainer/STGAN.py
PaddleCV/gan/trainer/STGAN.py
+5
-4
PaddleCV/gan/trainer/StarGAN.py
PaddleCV/gan/trainer/StarGAN.py
+1
-1
PaddleCV/gan/util/utility.py
PaddleCV/gan/util/utility.py
+15
-14
未找到文件。
PaddleCV/gan/data_reader.py
浏览文件 @
fcc4581e
...
...
@@ -296,7 +296,7 @@ class celeba_reader_creator(reader_creator):
label
=
np
.
array
(
label
).
astype
(
"float32"
)
label
=
(
label
+
1
)
//
2
img
=
CentorCrop
(
img
,
args
.
crop_size
,
args
.
crop_size
)
img
=
img
.
resize
((
args
.
load_size
,
args
.
load
_size
),
img
=
img
.
resize
((
args
.
image_size
,
args
.
image
_size
),
Image
.
BILINEAR
)
img
=
(
np
.
array
(
img
).
astype
(
'float32'
)
/
255.0
-
0.5
)
/
0.5
img
=
img
.
transpose
([
2
,
0
,
1
])
...
...
PaddleCV/gan/infer.py
浏览文件 @
fcc4581e
...
...
@@ -23,9 +23,10 @@ from PIL import Image
import
paddle.fluid
as
fluid
import
paddle
import
numpy
as
np
from
scipy.misc
import
imsave
import
imageio
import
glob
from
util.config
import
add_arguments
,
print_arguments
import
copy
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
add_arg
=
functools
.
partial
(
add_arguments
,
argparser
=
parser
)
...
...
@@ -153,7 +154,7 @@ def infer(args):
images
.
append
(
fake_temp
)
images_concat
=
np
.
concatenate
(
images
,
1
)
images_concat
=
np
.
concatenate
(
images_concat
,
1
)
im
sav
e
(
args
.
output
+
"/fake_img_"
+
name
[
0
],
(
im
ageio
.
imwrit
e
(
args
.
output
+
"/fake_img_"
+
name
[
0
],
(
(
images_concat
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
elif
args
.
model_net
==
'StarGAN'
:
test_reader
=
celeba_reader_creator
(
...
...
@@ -184,8 +185,8 @@ def infer(args):
fake_temp
=
np
.
squeeze
(
out
[
0
]).
transpose
([
1
,
2
,
0
])
images
.
append
(
fake_temp
)
images_concat
=
np
.
concatenate
(
images
,
1
)
im
save
(
out_path
+
"/fake_img"
+
str
(
epoch
)
+
"_"
+
name
[
0
],
(
(
images_concat
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
im
ageio
.
imwrite
(
out_path
+
"/fake_img"
+
str
(
epoch
)
+
"_"
+
name
[
0
],
(
(
images_concat
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
elif
args
.
model_net
==
'Pix2pix'
or
args
.
model_net
==
'cyclegan'
:
for
file
in
glob
.
glob
(
args
.
input
):
...
...
@@ -204,7 +205,7 @@ def infer(args):
fake_temp
=
np
.
squeeze
(
fake_temp
[
0
]).
transpose
([
1
,
2
,
0
])
input_temp
=
np
.
squeeze
(
data
).
transpose
([
1
,
2
,
0
])
im
sav
e
(
args
.
output
+
"/fake_"
+
image_name
,
(
im
ageio
.
imwrit
e
(
args
.
output
+
"/fake_"
+
image_name
,
(
(
fake_temp
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
else
:
raise
NotImplementedError
(
"model_net {} is not support"
.
format
(
...
...
PaddleCV/gan/trainer/AttGAN.py
浏览文件 @
fcc4581e
...
...
@@ -161,20 +161,21 @@ class DTrainer():
if
fluid
.
io
.
is_parameter
(
var
)
and
var
.
name
.
startswith
(
"discriminator"
):
vars
.
append
(
var
.
name
)
grad
=
fluid
.
gradients
(
pred
,
x
,
no_grad_set
=
vars
)
grad
=
fluid
.
gradients
(
pred
,
x
,
no_grad_set
=
vars
)
[
0
]
grad_shape
=
grad
.
shape
grad
=
fluid
.
layers
.
reshape
(
grad
,
[
-
1
,
grad_shape
[
1
]
*
grad_shape
[
2
]
*
grad_shape
[
3
]])
epsilon
=
1e-5
norm
=
fluid
.
layers
.
sqrt
(
fluid
.
layers
.
reduce_sum
(
fluid
.
layers
.
square
(
grad
),
dim
=
1
)
+
epsilon
)
fluid
.
layers
.
square
(
grad
),
dim
=
1
))
gp
=
fluid
.
layers
.
reduce_mean
(
fluid
.
layers
.
square
(
norm
-
1.0
))
return
gp
class
AttGAN
(
object
):
def
add_special_args
(
self
,
parser
):
parser
.
add_argument
(
'--image_size'
,
type
=
int
,
default
=
256
,
help
=
"image size"
)
parser
.
add_argument
(
'--g_lr'
,
type
=
float
,
...
...
@@ -241,7 +242,7 @@ class AttGAN(object):
self
.
batch_num
=
batch_num
def
build_model
(
self
):
data_shape
=
[
-
1
,
3
,
self
.
cfg
.
load_size
,
self
.
cfg
.
load
_size
]
data_shape
=
[
-
1
,
3
,
self
.
cfg
.
image_size
,
self
.
cfg
.
image
_size
]
image_real
=
fluid
.
layers
.
data
(
name
=
'image_real'
,
shape
=
data_shape
,
dtype
=
'float32'
)
...
...
PaddleCV/gan/trainer/STGAN.py
浏览文件 @
fcc4581e
...
...
@@ -159,20 +159,21 @@ class DTrainer():
if
fluid
.
io
.
is_parameter
(
var
)
and
var
.
name
.
startswith
(
"discriminator"
):
vars
.
append
(
var
.
name
)
grad
=
fluid
.
gradients
(
pred
,
x
,
no_grad_set
=
vars
)
grad
=
fluid
.
gradients
(
pred
,
x
,
no_grad_set
=
vars
)
[
0
]
grad_shape
=
grad
.
shape
grad
=
fluid
.
layers
.
reshape
(
grad
,
[
-
1
,
grad_shape
[
1
]
*
grad_shape
[
2
]
*
grad_shape
[
3
]])
epsilon
=
1e-5
norm
=
fluid
.
layers
.
sqrt
(
fluid
.
layers
.
reduce_sum
(
fluid
.
layers
.
square
(
grad
),
dim
=
1
)
+
epsilon
)
fluid
.
layers
.
square
(
grad
),
dim
=
1
))
gp
=
fluid
.
layers
.
reduce_mean
(
fluid
.
layers
.
square
(
norm
-
1.0
))
return
gp
class
STGAN
(
object
):
def
add_special_args
(
self
,
parser
):
parser
.
add_argument
(
'--image_size'
,
type
=
int
,
default
=
256
,
help
=
"image size"
)
parser
.
add_argument
(
'--g_lr'
,
type
=
float
,
...
...
@@ -246,7 +247,7 @@ class STGAN(object):
self
.
batch_num
=
batch_num
def
build_model
(
self
):
data_shape
=
[
-
1
,
3
,
self
.
cfg
.
load_size
,
self
.
cfg
.
load
_size
]
data_shape
=
[
-
1
,
3
,
self
.
cfg
.
image_size
,
self
.
cfg
.
image
_size
]
image_real
=
fluid
.
layers
.
data
(
name
=
'image_real'
,
shape
=
data_shape
,
dtype
=
'float32'
)
...
...
PaddleCV/gan/trainer/StarGAN.py
浏览文件 @
fcc4581e
...
...
@@ -185,7 +185,7 @@ class DTrainer():
for
var
in
fluid
.
default_main_program
().
list_vars
():
if
fluid
.
io
.
is_parameter
(
var
)
and
var
.
name
.
startswith
(
'd_'
):
vars
.
append
(
var
.
name
)
grad
=
fluid
.
gradients
(
pred
,
x
,
no_grad_set
=
vars
)
grad
=
fluid
.
gradients
(
pred
,
x
,
no_grad_set
=
vars
)
[
0
]
grad_shape
=
grad
.
shape
grad
=
fluid
.
layers
.
reshape
(
grad
,
[
-
1
,
grad_shape
[
1
]
*
grad_shape
[
2
]
*
grad_shape
[
3
]])
...
...
PaddleCV/gan/util/utility.py
浏览文件 @
fcc4581e
...
...
@@ -27,7 +27,8 @@ import six
matplotlib
.
use
(
'agg'
)
import
matplotlib.pyplot
as
plt
import
matplotlib.gridspec
as
gridspec
from
scipy.misc
import
imsave
import
imageio
import
copy
img_dim
=
28
...
...
@@ -94,11 +95,11 @@ def save_test_image(epoch,
input_A_temp
=
np
.
squeeze
(
data_A
[
0
]).
transpose
([
1
,
2
,
0
])
input_B_temp
=
np
.
squeeze
(
data_A
[
0
]).
transpose
([
1
,
2
,
0
])
im
sav
e
(
out_path
+
"/fakeB_"
+
str
(
epoch
)
+
"_"
+
name
,
(
im
ageio
.
imwrit
e
(
out_path
+
"/fakeB_"
+
str
(
epoch
)
+
"_"
+
name
,
(
(
fake_B_temp
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
im
sav
e
(
out_path
+
"/inputA_"
+
str
(
epoch
)
+
"_"
+
name
,
(
im
ageio
.
imwrit
e
(
out_path
+
"/inputA_"
+
str
(
epoch
)
+
"_"
+
name
,
(
(
input_A_temp
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
im
sav
e
(
out_path
+
"/inputB_"
+
str
(
epoch
)
+
"_"
+
name
,
(
im
ageio
.
imwrit
e
(
out_path
+
"/inputB_"
+
str
(
epoch
)
+
"_"
+
name
,
(
(
input_B_temp
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
elif
cfg
.
model_net
==
"StarGAN"
:
for
data
in
zip
(
A_test_reader
()):
...
...
@@ -127,8 +128,8 @@ def save_test_image(epoch,
images
.
append
(
fake_temp
)
images
.
append
(
rec_temp
)
images_concat
=
np
.
concatenate
(
images
,
1
)
im
save
(
out_path
+
"/fake_img"
+
str
(
epoch
)
+
"_"
+
name
[
0
],
(
(
images_concat
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
im
ageio
.
imwrite
(
out_path
+
"/fake_img"
+
str
(
epoch
)
+
"_"
+
name
[
0
],
(
(
images_concat
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
elif
cfg
.
model_net
==
'AttGAN'
or
cfg
.
model_net
==
'STGAN'
:
for
data
in
zip
(
A_test_reader
()):
real_img
,
label_org
,
name
=
data
[
0
]
...
...
@@ -168,8 +169,8 @@ def save_test_image(epoch,
images
.
append
(
fake_temp
)
images_concat
=
np
.
concatenate
(
images
,
1
)
images_concat
=
np
.
concatenate
(
images_concat
,
1
)
im
save
(
out_path
+
"/fake_img"
+
str
(
epoch
)
+
'_'
+
name
[
0
],
(
(
images_concat
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
im
ageio
.
imwrite
(
out_path
+
"/fake_img"
+
str
(
epoch
)
+
'_'
+
name
[
0
],
(
(
images_concat
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
else
:
for
data_A
,
data_B
in
zip
(
A_test_reader
(),
B_test_reader
()):
...
...
@@ -194,17 +195,17 @@ def save_test_image(epoch,
input_A_temp
=
np
.
squeeze
(
data_A
[
0
][
0
]).
transpose
([
1
,
2
,
0
])
input_B_temp
=
np
.
squeeze
(
data_B
[
0
][
0
]).
transpose
([
1
,
2
,
0
])
im
sav
e
(
out_path
+
"/fakeB_"
+
str
(
epoch
)
+
"_"
+
A_name
,
(
im
ageio
.
imwrit
e
(
out_path
+
"/fakeB_"
+
str
(
epoch
)
+
"_"
+
A_name
,
(
(
fake_B_temp
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
im
sav
e
(
out_path
+
"/fakeA_"
+
str
(
epoch
)
+
"_"
+
B_name
,
(
im
ageio
.
imwrit
e
(
out_path
+
"/fakeA_"
+
str
(
epoch
)
+
"_"
+
B_name
,
(
(
fake_A_temp
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
im
sav
e
(
out_path
+
"/cycA_"
+
str
(
epoch
)
+
"_"
+
A_name
,
(
im
ageio
.
imwrit
e
(
out_path
+
"/cycA_"
+
str
(
epoch
)
+
"_"
+
A_name
,
(
(
cyc_A_temp
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
im
sav
e
(
out_path
+
"/cycB_"
+
str
(
epoch
)
+
"_"
+
B_name
,
(
im
ageio
.
imwrit
e
(
out_path
+
"/cycB_"
+
str
(
epoch
)
+
"_"
+
B_name
,
(
(
cyc_B_temp
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
im
sav
e
(
out_path
+
"/inputA_"
+
str
(
epoch
)
+
"_"
+
A_name
,
(
im
ageio
.
imwrit
e
(
out_path
+
"/inputA_"
+
str
(
epoch
)
+
"_"
+
A_name
,
(
(
input_A_temp
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
im
sav
e
(
out_path
+
"/inputB_"
+
str
(
epoch
)
+
"_"
+
B_name
,
(
im
ageio
.
imwrit
e
(
out_path
+
"/inputB_"
+
str
(
epoch
)
+
"_"
+
B_name
,
(
(
input_B_temp
+
1
)
*
127.5
).
astype
(
np
.
uint8
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录