### 11. CycleGAN与非配对图像转换
本节的程序来源于项目https://github.com/vanhuyz/CycleGAN-TensorFlow,并做了细微修改。
**11.2.1 下载数据集并训练**
下载一个事先准备好的数据集:
```
bash download_dataset.sh apple2orange
```
将图片转换成tfrecords格式:
```
python build_data.py \
--X_input_dir data/apple2orange/trainA \
--Y_input_dir data/apple2orange/trainB \
--X_output_file data/tfrecords/apple.tfrecords \
--Y_output_file data/tfrecords/orange.tfrecords
```
训练模型:
```
python train.py \
--X data/tfrecords/apple.tfrecords \
--Y data/tfrecords/orange.tfrecords \
--image_size 256
```
打开TensorBoard(需要将--logdir checkpoints/20170715-1622 中的目录替换为自己机器中的对应目录):
```
tensorboard --logdir checkpoints/20170715-1622
```
导出模型(同样要注意将20170715-1622 替换为自己机器中的对应目录):
```
python export_graph.py \
--checkpoint_dir checkpoints/20170715-1622 \
--XtoY_model apple2orange.pb \
--YtoX_model orange2apple.pb \
--image_size 256
```
使用测试集中的图片进行测试:
```
python inference.py \
--model pretrained/apple2orange.pb \
--input data/apple2orange/testA/n07740461_1661.jpg \
--output data/apple2orange/output_sample.jpg \
--image_size 256
```
转换生成的图片保存在data/apple2orange/output_sample. jpg。
**11.2.2 使用自己的数据进行训练**
在chapter_11_data/中,事先提供了一个数据集man2woman.zip。,解压后共包含两个文件夹:a_resized 和b_resized。将它们放到目录~/datasets/man2woman/下。使用下面的命令将数据集转换为tfrecords:
```
python build_data.py \
--X_input_dir ~/datasets/man2woman/a_resized/ \
--Y_input_dir ~/datasets/man2woman/b_resized/ \
--X_output_file ~/datasets/man2woman/man.tfrecords \
--Y_output_file ~/datasets/man2woman/woman.tfrecords
```
训练:
```
python train.py \
--X ~/datasets/man2woman/man.tfrecords \
--Y ~/datasets/man2woman/woman.tfrecords \
--image_size 256
```
导出模型和测试图片的指令可参考11.2.1。
#### 拓展阅读
- 本章主要讲了模型CycleGAN , 读者可以参考论文Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks 了解更多细节
- CycleGAN 不需要成对数据就可以训练,具有较强的通用性,由此产生了大量有创意的应用,例如男女互换(即本章所介绍的)、猫狗互换、利用手绘地图还原古代城市等。可以参考https://zhuanlan.zhihu.com/p/28342644 以及https://junyanz.github.io/CycleGAN/ 了解这些有趣的实验
- CycleGAN 可以将将某一类图片转换成另外一类图片。如果想要把一张图片转换为另外K类图片,就需要训练K个CycleGAN,这是比较麻烦的。对此,一种名为StarGAN 的方法改进了CycleGAN, 可以只用一个模型完成K类图片的转换,有兴趣的读者可以参阅其论文StarGAN: Unified Generative Adversarial Networks for Multi-Domain Image-to-Image Translation。
- 如果读者还想学习更多和GAN 相关的模型, 可以参考 https://github.com/hindupuravinash/the-gan-zoo 。这里列举了迄今几乎所有的名字中带有“GAN”的模型和相应的论文。
没有合适的资源?快使用搜索试试~ 我知道了~
CycleGan的源码(TensorFlow)和论文
共41个文件
jpg:16个
py:10个
pyc:6个
需积分: 45 51 下载量 44 浏览量
2018-07-01
10:35:16
上传
评论 4
收藏 5MB ZIP 举报
温馨提示
CycleGan的源码(TensorFlow)和论文CycleGan的源码(TensorFlow)和论文
资源推荐
资源详情
资源评论
收起资源包目录
Cycle-GAN.zip (41个子文件)
Cycle-GAN
.gitignore 1KB
export_graph.py 2KB
Makefile 1KB
data
samples
fake_orange2apple_1.jpg 29KB
fake_orange2apple_3.jpg 35KB
real_apple2orange_4.jpg 54KB
train_screenshot.png 1.04MB
real_orange2apple_3.jpg 54KB
real_orange2apple_4.jpg 38KB
fake_apple2orange_4.jpg 33KB
real_orange2apple_2.jpg 56KB
real_orange2apple_1.jpg 50KB
fake_apple2orange_3.jpg 30KB
real_apple2orange_1.jpg 51KB
fake_orange2apple_4.jpg 23KB
real_apple2orange_3.jpg 45KB
real_apple2orange_2.jpg 37KB
fake_orange2apple_2.jpg 35KB
fake_apple2orange_1.jpg 31KB
fake_apple2orange_2.jpg 29KB
LICENSE 1KB
inference.py 2KB
discriminator.py 2KB
README_eng.md 5KB
utils.py 1KB
checkpoints
20180626-2123
events.out.tfevents.1530019439.LITZ-PC 16.32MB
README.md 3KB
__pycache__
discriminator.cpython-35.pyc 1KB
generator.cpython-35.pyc 2KB
model.cpython-35.pyc 6KB
utils.cpython-35.pyc 2KB
ops.cpython-35.pyc 8KB
reader.cpython-35.pyc 3KB
reader.py 3KB
ops.py 7KB
download_dataset.sh 898B
build_data.py 3KB
generator.py 2KB
Zhu_Unpaired_Image-To-Image_Translation_ICCV_2017_paper.pdf 2.35MB
model.py 7KB
train.py 5KB
共 41 条
- 1
资源评论
jeffery0628
- 粉丝: 39
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功