当前位置:网站首页>从零开始实现一个简单的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 对你有帮助:)
边栏推荐
猜你喜欢
浅谈web网站架构演变过程
什么是网站监控,网站监控软件有什么用?
开篇-开启全新的.NET现代应用开发体验
【软件工程之美 - 专栏笔记】37 | 遇到线上故障,你和高手的差距在哪里?
用Excel绘制统计图
【STM32】入门(五):串口TTL、RS232、RS485
How does the intelligent video surveillance platform EasyCVR use the interface to export iframe addresses in batches?
Matlab drawing 1
DHCP&OSPF组合实验演示(Huawei路由交换设备配置)
测试/开发程序员男都秃头?女都满脸痘痘?过好我们“短暂“的一生......
随机推荐
CAN光纤转换器CAN光端机解决消防火灾报警
mq消息积压怎么对应
在线生成接口文档
GBase8s存储过程
VPC2187/8 current mode PWM controller 4-100VIN ultra-wide voltage startup, highly integrated power control chip recommended
DOM Clobbering的原理及应用
The Industrial Metaverse Brings Changes to Industry
部署LVS-DR群集
ACP-Cloud Computing By Wakin自用笔记(2)CPU和内存虚拟化
VPC2187/8 电流模式 PWM 控制器 4-100VIN 超宽压启动、高度集成电源控制芯片推荐
Develop those things: How to obtain the traffic statistics of the monitoring site through the EasyCVR platform?
Alibaba Cloud International Edition uses ROS to build WordPress tutorial
win10 uwp 修改Pivot Header 颜色
基于激励的需求响应计划下弹性微电网的短期可靠性和经济性评估(Matlab代码实现)
在表格数据集上训练变分自编码器 (VAE)示例
火灾报警联网FC18中CAN光端机常见问题解答和使用指导
BigDecimal 使用注意!!“别踩坑”
测试/开发程序员男都秃头?女都满脸痘痘?过好我们“短暂“的一生......
win10 uwp DataContext
用Excel绘制统计图