github源代码:GitHub - junyanz/pytorch-CycleGAN-and-pix2pix: Image-to-Image Translation in PyTorch

论文详解:http://t.csdn.cn/q9hUS

二、运行代码

1.下载源代码

cd ~/zhw
git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix
cd pytorch-CycleGAN-and-pix2pixconda env create -f environment.yml #创建conda环境
conda activate pytorch-CycleGAN-and-pix2pix #激活conda环境

如下图,在conda(pytorch-CycleGAN-and-pix2pix)环境中运行代码。

2.准备数据集

“prepare_ACDC_datasets.py”将数据集ACDC/night中图片均裁成1:1的.jpg格式,保存在“./zhw/pytorch-CycleGAN-and-pix2pix/datasets/ACDC/day2night”,数据集文件需要如下形式 ,其中B为normal情况,A为night。

3.train训练

可以通过visdom在训练过程中查看训练情况和loss损失,在训练前开启visdom,用法如下:

pip install visdom
python -m visdom.server##如果Error: Address already in use.
lsof -i tcp:8097
kill -9 xxx #xxx被占用的pid号码
lsof -i tcp:8097
python3 -m visdom.server

如果出现'Address already in use'的错误,参考http://t.csdn.cn/0ZWin。

点击网址localhost:8097,发现仍然出错tornado,网址无法打开,则参考http://t.csdn.cn/ifO1r:

1.在github下载下载visdom-master代码;GitHub - fossasia/visdom: A flexible tool for creating, organizing, and sharing visualizations of live, rich data. Supports Torch and Numpy.2.先在‘visdom-master\py\visdom\server.py’接近文件结尾处注释download_scripts

3.找到visdom-master\py\visdom\static\index.html替换为如下内容html;

4.将下载的static文件夹替换到‘anaconda/envs/环境名/lib/python3.6/site-packages/visdom/static’。static文件夹压缩包见我发布的资源。

<!--Copyright 2017-present, Facebook, Inc.
All rights reserved.This source code is licensed under the license found in the
LICENSE file in the root directory of this source tree.--><!doctype html>
<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="shortcut icon" href="favicon.png"><!-- Bootstrap & jQuery --><link rel="stylesheet" href={{ static_url("css/bootstrap.min.css") }}><script src={{ static_url("js/jquery.min.js") }}></script><script src={{ static_url("js/bootstrap.min.js") }}></script><link rel="stylesheet" href={{ static_url("css/react-resizable-styles.css") }}><link rel="stylesheet" href={{ static_url("css/react-grid-layout-styles.css") }}><!-- Other deps --><script src={{ static_url("js/react-react.min.js") }}></script><script src={{ static_url("js/react-dom.min.js") }}></script><script src={{ static_url("fonts/layout_bin_packer") }}></script><!-- Mathjax --><script type="text/javascript" async src={{ static_url("js/mathjax-MathJax.js") }}></script><!-- Plotly --><script src={{ static_url("js/plotly-plotly.min.js") }}></script><!-- Custom styles for this template --><script>// TODO: this is not great. Should probably be an endpoint with a JSON// response or the first thing the socket sends back.var ENV_LIST = [{% for item in items %}'{{escape(item)}}',{% end %}];var ACTIVE_ENV = '{{escape(active_item)}}';var USER = '{{escape(user)}}';// Plotly setupwindow.PLOTLYENV = window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL = 'https://plot.ly';</script><script src={{ static_url("js/main.js") }}></script><link rel="stylesheet" href={{ static_url("css/style.css") }}><title>visdom</title><!-- <link rel="icon" href="http://example.com/favicon.png"> --></head><body><noscript>JS is required</noscript><div id="app"></div></body>
</html>

点击网址,若visdom运行成功则在开始训练后开始如下界面:

开启visdom后训练,训练结束的模型存放在'checkpoints/FDA/day2night_cyclegan/'。

#!./scripts/train_cyclegan.sh
python train.py --dataroot ./datasets/ACDC/night/day2night/ --name day2night_cyclegan --model cycle_gan

最后day2night和day2rain模型训练过程loss趋势图如下,是收敛的。

4.test测试

#!./scripts/test_cyclegan.sh
python test.py --dataroot ./datasets/ACDC/night/day2night/ --name day2night_cyclegan --model cycle_gan

测试结果在'./results/day2night_cyclegan/latest_test/index.html',包括real、fake、rec。realA为A原图,fakeA为B转换为A风格的结果,recA为A转换到B风格再回到A风格的结果F(G(A))。测试结果如下:

5.应用模型

训练前需要在'./model/base_model.py'line192修改参数。test和apply代码修改不同:

load_filename='%s_net_%s' %(epoch,name) #test
load_filename='%s_net_%s_B' %(epoch,name) #apply:day2night
load_filename='%s_net_%s_A' %(epoch,name) #apply:day2rain

在'./option/test_option.py'需要修改转换风格后图像存储位置'--results='和转换数量'--num_test'。test与apply代码略有不同,结果存放在'./results/day2rain_cyclegan'。文件包含'_A_fake.jpg'为normal的cityscapes转换为night风格的结果,其对应labels存放在'./datasets/cityscapes/testB'。

##day2night
python test.py --dataroot datasets/cityscapes1/testB --name day2night_cyclegan --model test --no_dropout##day2rain
python test.py --dataroot datasets/cityscapes1/testA --name day2rain_cyclegan --model test --no_dropout

论文pytorch-CycleGAN-and-pix2pix相关推荐

  1. CycleGAN与pix2pix不得不玩的模型

    CycleGAN是在去年三月底放在arxiv的一篇文章,文章名为Learning to Discover Cross-Domain Relations with Generative Adversar ...

  2. Transformer-XL解读(论文 + PyTorch源码)

    前言 目前在NLP领域中,处理语言建模问题有两种最先进的架构:RNN和Transformer.RNN按照序列顺序逐个学习输入的单词或字符之间的关系,而Transformer则接收一整段序列,然后使用s ...

  3. Python基于CycleGAN&pix2pix的黑白图像AI上色(源码&部署教程)

    1.项目背景 自从GAN技术发展以来,许多新奇的应用都得到了落地,本次我们来介绍其中一个小应用,就是黑白图像上色.想必大家在网上经常看到一些给黑白图像上色的视频,可以修复早期的黑白影像,背后的技术就是 ...

  4. CycleGAN与pix2pix训练自己的数据集-Pytorch

    github:https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix 参考:https://blog.csdn.net/Gavinmiaoc/a ...

  5. 深度学习论文代码复现——CycleGAN和pix2pix

    一:前期代码准备 从GitCode(服务器在国内,访问比较快)中将开源代码copy下来 地址:mirrors / junyanz / pytorch-cyclegan-and-pix2pix · Gi ...

  6. 【生成对抗网络 论文泛读】……pix2pix pix2pixhd……

    文章目录 前言 Pix2pix 简介 核心思想 Pix2pixHD 升级1 升级2 升级3 升级4 前言 这两篇论文放在一起说. pix2pix:点我下载 pix2pixhd:点我下载 Pix2pix ...

  7. ELMo解读(论文 + PyTorch源码)

    ELMo的概念也是很早就出了,应该是18年初的事情了.但我仍然是后知后觉,居然还是等BERT出来很久之后,才知道有这么个东西.这两天才仔细看了下论文和源码,在这里做一些记录,如果有不详实的地方,欢迎指 ...

  8. TensorFlow王位不保?ICLR投稿论文PyTorch出镜率快要反超了

    自PyTorch出道以来,不断有人表示,发现了这样的趋势: "学术圈正在慢慢地抛弃TensorFlow,转投PyTorch." 如今,PyTorch 1.0发布,ICLR 2019 ...

  9. 心中无码,自然高清 | 联合去马赛克与超分辨率研究论文Pytorch复现

    作者 | 知凡,个人公众号:林木蔚然读书会(ID:EspressoOcean),知乎ID:Uno Whoiam 本文授权转载自知乎 本文结构 简单扫盲 什么是去马赛克 什么是超分辨率 <Deep ...

  10. pytorch cycleGAN代码学习1

    一. 新的东西 p.s :很多架构都和之前一样,就举些不同的 1. ReplayBuffer() # Buffers of previously generated samples   fake_A_ ...

最新文章

  1. 2016/05/03(接口 买票 临界资源同步锁)
  2. linux下oracle自启动
  3. 查找unity工程代码中中文字符
  4. 【ArcGIS遇上Python】python批量获取栅格数据四至(top,bottom,left,right)坐标代码
  5. linux nginx 状态,Nginx开启运行状态(status)功能 | IT运维网
  6. 从源码角度看Spark on yarn client cluster模式的本质区别
  7. 微信内打开的网页不能下载APP,微信无法打开浏览器访问指定页面的解决方案...
  8. android 友盟推送获取不到devicetoken,使用友盟消息推送中遇到的哪些问题--索引(开发者必读)...
  9. stream判断数组长度大于0_java8 stream:检查list集合中是否存在某个值
  10. mongodb可视化工具robo3T的安装和使用
  11. docker es持久化_docker如何保持数据持久化?其实可以考虑通过数据卷挂载的方式~...
  12. python selenium爬虫工具
  13. pytorch时空数据处理4——图像转文本/字幕Image-Captionning(二)
  14. d3力导向图增加节点_在D3力导向图中突出显示所选节点,其链接及其子节点
  15. Zotero-无法打开zotero数据库
  16. C++中用两个栈实现一个队列
  17. 开平方的快速算法(C程序)
  18. 保利威视后台录屏类视频清晰度优化说明
  19. Dell R730服务器inter 500系列网卡与光模块不兼容**
  20. unicode编码和utf-8编码的区别

热门文章

  1. 巧用美女照做微信吸粉,你会做吗?
  2. AD 脚本kixtart运用之四(用户桌面背景)
  3. 【Android-I】Android开发之常见错误:Dx unsupported class file version 52.0...while parsing com/...
  4. UVM TLM2: SystemC和SV 通信
  5. Nubia Z5S(高通公司MSM8974) QHSUSB_BULK砖的方法节省模式(随着win7在恢复recovery分区案例)...
  6. asp.net(入门理解)
  7. 安装失败,CentOS 7 安装 安卓模拟器
  8. 微信在后台疯狂读取用户隐私?专家:乌龙!是苹果系统升级的锅...你怎么看?...
  9. TCL/TK文件操作
  10. XenDesktop中如何重定向USB设备