当前位置:网站首页>从零开始实现一个简单的CycleGAN项目
从零开始实现一个简单的CycleGAN项目
2022-08-04 18:41:00 【江户川柯壮】
项目地址:https://github.com/jzsherlock4869/cyclegan-pytorch
pytorch 中CycleGAN(循环一致生成对抗网络)的简单且易于修改的实现
CycleGAN 的基本说明(来自原始论文):

使用“horse2zebra”数据集重新实现此 repo 的结果(没有参数调整,仍然有一些明显的伪影,您可以调整超参数以使其更好~)


安装和准备
下载 CycleGAN 的常用数据集并使用它们来训练和验证代码管道
Monet-Photo 传输:Kaggle Monet-Photo 传输
Horse-Zebra 转移:Kaggle Horse-Zebra 转移
然后按以下结构准备数据集文件夹:
├── monet_dataset
│ ├── monet_jpg
│ └── photo_jpg
└── zebra_dataset
├── testA
├── testB
├── trainA
└── trainB
Git 克隆这个 repo 并 cd 到根文件夹
git clone https://github.com/jzsherlock4869/cyclegan-pytorch
cd cyclegan-python
根据requirements.txt文件夹中的安装必要的python包
开始训练
将 dataroot 修改config/000_base_cyclegan_horse2zebra.yml为您自己的数据集路径,然后运行训练过程:
python train_cyclegan.py --opt configs/000_base_cyclegan_horse2zebra.yml
“ horse2zebra ”和“ photo2monet ”的数据集类已经在这个 repo 中实现。
get_photo2monet_train_dataloader要在您自己的数据集(域 A 和域 B)上进行训练,请将您自己的数据加载器编写 get_horse2zebra_train_dataloader为 data/sample_dataloader.py
def get_your_custom_train_dataloader(root_dir="your_path",
batch_size=8,
img_size=(256, 256)):
imgA_sub, imgB_sub = "subdirnameA", "subdirnameB" # sub directory name to your root_dir
postfix_set=["jpg"] # which postfix is your images
train_dataset = CycleGANDataset(root_dir, imgA_sub, imgB_sub, postfix_set, img_size)
train_dataloader = DataLoader(train_dataset, batch_size=batch_size, shuffle=False)
return train_dataloader
然后修改第train_cyclegan.py54-60 行以添加您的数据集(记得先导入它们!)
if which_dataset == 'horse2zebra':
train_dataloader = get_horse2zebra_train_dataloader(dataroot,
batch_size=batch_size,
img_size=img_size)
elif which_dataset == 'photo2monet':
train_dataloader = get_photo2monet_train_dataloader(dataroot,
batch_size=batch_size,
img_size=img_size)
# add lines here
elif which_dataset == 'your_custom_dataset':
train_dataloader = get_your_custom_train_dataloader(dataroot,
batch_size=batch_size,
img_size=img_size)
#add lines here
else:
raise NotImplementedError(f"Unrecognized dataset type : {which_dataset}")
参考
这段代码是对 CycleGAN 的重新实现,更易于理解和修改,尤其适合初学者。原论文是:
@inproceedings{CycleGAN2017, title={Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networkss}, author={Zhu, Jun-Yan and Park, Taesung and Isola, Phillip and Efros, Alexei A}, booktitle={Computer Vision (ICCV), 2017 IEEE International Conference on}, year={2017} }
一个keras版本和教程,详细解释了CycleGAN的理论和过程:
https://machinelearningmastery.com/cyclegan-tutorial-with-keras/
而且,这个代码库的代码架构和风格也参考了BasicSR和UnpairedSR,部分功能直接借鉴。欣赏他们的好作品~
欢迎star如果这个 repo 对你有帮助:)
边栏推荐
- The CPU suddenly soars and the system responds slowly, what is the cause?Is there any way to check?
- win10 uwp MVVM 轻量框架
- 如何进行自动化测试?
- HCIP-R&S By Wakin自用笔记(1)企业网络高级解决方案
- The upgrade of capacity helps the flow of computing power, the acceleration moment of China's digital economy
- LVS负载均衡群集之原理叙述
- 使用.NET简单实现一个Redis的高性能克隆版(二)
- Regardless of whether you are a public, professional or non-major class, I have been sorting out the learning route for a long time here, and the learning route I have summarized is not yet rolled up
- win10 uwp json
- [Distributed Advanced] Let's fill in those pits in Redis distributed locks.
猜你喜欢
随机推荐
Flask framework implementations registered encryption, a Flask enterprise class learning 】 【
八一建军节 | 致敬中国人民解放军
基于激励的需求响应计划下弹性微电网的短期可靠性和经济性评估(Matlab代码实现)
谁能解答?从mysql的binlog读取数据到kafka,但是数据类型有Insert,updata,
LVS负载均衡群集之原理叙述
面试官:MVCC是如何实现的?
MySQL安装教程(详细)
CIFAR发布《AI伦理的文化:研讨会报告》【附下载】
【web自动化测试】playwright安装失败怎么办
什么是网站监控,网站监控软件有什么用?
Flask框架实现注册加密功能详解【Flask企业课学习】
动态数组底层是如何实现的
A group of friends asked for help, but the needs that were not solved in a week were solved in 3 minutes?
Matlab drawing 1
[Distributed Advanced] Let's fill in those pits in Redis distributed locks.
PHP代码审计9—代码执行漏洞
如何封装 svg
当前最快的实例分割模型:YOLACT 和 YOLACT++
关于使用腾讯云HiFlow场景连接器每天提醒签到打卡
VPC2187/8 电流模式 PWM 控制器 4-100VIN 超宽压启动、高度集成电源控制芯片推荐









