Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
8afd79b2
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看板
未验证
提交
8afd79b2
编写于
2月 12, 2020
作者:
X
xiaoting
提交者:
GitHub
2月 12, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix cyclegan download (#4198)
* fix cyclegan download
上级
5e1f7310
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
112 addition
and
4 deletion
+112
-4
dygraph/cycle_gan/README.md
dygraph/cycle_gan/README.md
+15
-3
dygraph/cycle_gan/download.py
dygraph/cycle_gan/download.py
+1
-1
dygraph/cycle_gan/generate_txt.py
dygraph/cycle_gan/generate_txt.py
+25
-0
dygraph/cycle_gan/prepare_cityscapes_dataset.py
dygraph/cycle_gan/prepare_cityscapes_dataset.py
+71
-0
未找到文件。
dygraph/cycle_gan/README.md
浏览文件 @
8afd79b2
...
...
@@ -35,12 +35,24 @@ Cycle GAN 是一种image to image 的图像生成网络,实现了非对称图
## 数据准备
本教程使用 cityscapes 数据集 来进行模型的训练测试工作,可以通过指定
`python download.py --dataset cityscapes
`
下载得到。
CycleGAN 支持的数据集可以参考download.py中的
`cycle_pix_dataset`
,可以通过指定
`python download.py --dataset xxx
`
下载得到。
cityscapes 训练集包含2975张街景实拍图片,2975张对应真实街景的语义分割图片。测试集包含499张实拍图片和499张语义分割图片。
由于版权问题,cityscapes 数据集无法通过脚本直接获得,需要从
[
官方
](
https://www.cityscapes-dataset.com/
)
下载数据,
下载完之后执行
`python prepare_cityscapes_dataset.py --gtFine_dir ./gtFine/ --leftImg8bit_dir ./leftImg8bit --output_dir ./data/cityscapes/`
处理,
将数据存放在
`data/cityscapes`
。
数据下载处理完毕后,并组织为以下路径结构:
数据下载处理完毕后,需要您将数据组织为以下路径结构:
```
data
|-- cityscapes
| |-- testA
| |-- testB
| |-- trainA
| |-- trainB
```
然后运行txt生成脚本:
`python generate_txt.py`
,最终数据组织如下所示:
```
data
|-- cityscapes
...
...
dygraph/cycle_gan/download.py
浏览文件 @
8afd79b2
...
...
@@ -153,7 +153,7 @@ if __name__ == '__main__':
args
=
parser
.
parse_args
()
cycle_pix_dataset
=
[
'apple2orange'
,
'summer2winter_yosemite'
,
'horse2zebra'
,
'monet2photo'
,
'cezanne2photo'
,
'ukiyoe2photo'
,
'vangogh2photo'
,
'maps'
,
'cityscapes'
,
'cezanne2photo'
,
'ukiyoe2photo'
,
'vangogh2photo'
,
'maps'
,
'facades'
,
'iphone2dslr_flower'
,
'ae_photos'
,
'mini'
]
...
...
dygraph/cycle_gan/generate_txt.py
0 → 100644
浏览文件 @
8afd79b2
import
sys
import
os
import
argparse
def
gen_txt
(
dir_path
):
dataname
=
"cityscapes"
### generator .txt file according to dirs
dirs
=
os
.
listdir
(
os
.
path
.
join
(
dir_path
,
'{}'
.
format
(
dataname
)))
for
d
in
dirs
:
txt_file
=
d
+
'.txt'
txt_dir
=
os
.
path
.
join
(
dir_path
,
dataname
)
f
=
open
(
os
.
path
.
join
(
txt_dir
,
txt_file
),
'w'
)
for
fil
in
os
.
listdir
(
os
.
path
.
join
(
txt_dir
,
d
)):
wl
=
d
+
'/'
+
fil
+
'
\n
'
f
.
write
(
wl
)
f
.
close
()
sys
.
stderr
.
write
(
"
\n
"
)
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
# yapf: disable
parser
.
add_argument
(
'--output_dir'
,
type
=
str
,
default
=
"datasets"
,
help
=
'Path to output Cityscapes directory.'
)
# yapf: enable
args
=
parser
.
parse_args
()
gen_txt
(
args
.
output_dir
)
\ No newline at end of file
dygraph/cycle_gan/prepare_cityscapes_dataset.py
0 → 100644
浏览文件 @
8afd79b2
import
os
import
argparse
import
functools
import
glob
import
sys
from
PIL
import
Image
''' Based on https://github.com/junyanz/CycleGAN'''
def
load_image
(
path
):
return
Image
.
open
(
path
).
convert
(
'RGB'
).
resize
((
256
,
256
))
def
propress_cityscapes
(
gtFine_dir
,
leftImg8bit_dir
,
output_dir
,
phase
):
save_dir
=
os
.
path
.
join
(
output_dir
,
phase
)
try
:
os
.
makedirs
(
save_dir
)
except
Exception
as
e
:
print
(
"{} makedirs"
.
format
(
e
))
pass
try
:
os
.
makedirs
(
save_dir
+
'A'
)
except
Exception
as
e
:
print
(
"{} makedirs"
.
format
(
e
))
try
:
os
.
makedirs
(
save_dir
+
'B'
)
except
Exception
as
e
:
print
(
"{} makedirs"
.
format
(
e
))
seg_expr
=
os
.
path
.
join
(
gtFine_dir
,
phase
,
"*"
,
"*_color.png"
)
seg_paths
=
glob
.
glob
(
seg_expr
)
seg_paths
=
sorted
(
seg_paths
)
photo_expr
=
os
.
path
.
join
(
leftImg8bit_dir
,
phase
,
"*"
,
'*_leftImg8bit.png'
)
photo_paths
=
glob
.
glob
(
photo_expr
)
photo_paths
=
sorted
(
photo_paths
)
assert
len
(
seg_paths
)
==
len
(
photo_paths
),
\
"[%d] gtFine images NOT match [%d] leftImg8bit images. Aborting."
%
(
len
(
seg_paths
),
len
(
photo_paths
))
for
i
,
(
seg_path
,
photo_path
)
in
enumerate
(
zip
(
seg_paths
,
photo_paths
)):
seg_image
=
load_image
(
seg_path
)
photo_image
=
load_image
(
photo_path
)
# save image
save_path
=
os
.
path
.
join
(
save_dir
+
'A'
,
"%d_A.jpg"
%
i
)
photo_image
.
save
(
save_path
,
format
=
'JPEG'
,
subsampling
=
0
,
quality
=
100
)
save_path
=
os
.
path
.
join
(
save_dir
+
'B'
,
"%d_B.jpg"
%
i
)
seg_image
.
save
(
save_path
,
format
=
'JPEG'
,
subsampling
=
0
,
quality
=
100
)
if
i
%
10
==
0
:
print
(
"proprecess %d ~ %d images."
%
(
i
,
i
+
10
))
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
# yapf: disable
parser
.
add_argument
(
'--gtFine_dir'
,
type
=
str
,
default
=
None
,
help
=
'Path to Cityscapes gtFine directory.'
)
parser
.
add_argument
(
'--leftImg8bit_dir'
,
type
=
str
,
default
=
None
,
help
=
'Path to Cityscapes leftImg8bit_trainvaltest directory.'
)
parser
.
add_argument
(
'--output_dir'
,
type
=
str
,
default
=
None
,
help
=
'Path to output Cityscapes directory.'
)
# yapf: enable
args
=
parser
.
parse_args
()
print
(
'Preparing Cityscapes Dataset for test phase'
)
propress_cityscapes
(
args
.
gtFine_dir
,
args
.
leftImg8bit_dir
,
args
.
output_dir
,
'test'
)
print
(
'Preparing Cityscapes Dataset for train phase'
)
propress_cityscapes
(
args
.
gtFine_dir
,
args
.
leftImg8bit_dir
,
args
.
output_dir
,
'train'
)
print
(
"DONE!!!"
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录