当前位置:网站首页>从零开始实现一个简单的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 对你有帮助:)
边栏推荐
- 基于 eBPF 的 Kubernetes 可观测实践
- 【CCIG 2022】视觉大模型论坛
- 实验室专利书写指南
- 袋鼠云思枢:数驹DTengine,助力企业构建高效的流批一体数据湖计算平台
- Flask框架实现注册加密功能详解【Flask企业课学习】
- Thrift installation configuration
- Google Earth Engine APP - one-click online viewing of global images from 1984 to this year and loading an image analysis at the same time
- lc marathon 8.3
- 股票开户广发证券,网上开户安全吗?
- Alibaba Cloud International Edition uses ROS to build WordPress tutorial
猜你喜欢

MMDetection 使用示例:从入门到出门

The upgrade of capacity helps the flow of computing power, the acceleration moment of China's digital economy

MySQL安装教程(详细)

EasyCVR本地接入国标设备映射公网后,本地设备出现无法播放与级联的解决方法

智能视频监控平台EasyCVR如何使用接口批量导出iframe地址?

PHP代码审计10—命令执行漏洞

(ECCV-2022)GaitEdge:超越普通的端到端步态识别,提高实用性

【STM32】入门(五):串口TTL、RS232、RS485

火灾报警联网FC18中CAN光端机常见问题解答和使用指导

链表的经典入门LeetCode题目
随机推荐
win10 uwp 使用 Geometry resources 在 xaml
2019年海淀区青少年程序设计挑战活动小学组复赛试题详细答案
ATF中断处理的设计模型
【杰神说说】物联大师2.0版本预告
EuROC dataset format and related codes
Documentary on Security Reinforcement of Network Range Monitoring System (1)—SSL/TLS Encrypted Transmission of Log Data
[Distributed Advanced] Let's fill in those pits in Redis distributed locks.
情绪的波动起伏
DHCP&OSPF组合实验演示(Huawei路由交换设备配置)
关于使用腾讯云HiFlow场景连接器每天提醒签到打卡
报道称任天堂在2023年3月前不会推出任何新硬件产品
【软件工程之美 - 专栏笔记】37 | 遇到线上故障,你和高手的差距在哪里?
不论你是大众,科班和非科班,我这边整理很久,总结出的学习路线,还不快卷起来
EuROC 数据集格式及相关代码
CPU突然飙高系统反应慢,是怎么导致的?有什么办法排查?
Day018 Inheritance
谁能解答?从mysql的binlog读取数据到kafka,但是数据类型有Insert,updata,
自己经常使用的三种调试:Pycharm、Vscode、pdb调试
unity中实现ue眼球的渲染
机器学习——线性回归