当前位置:   article > 正文

论文pytorch-CycleGAN-and-pix2pix_论文pytorch cyclegan源代码下载

论文pytorch cyclegan源代码下载

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

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

二、运行代码

1.下载源代码

  1. cd ~/zhw
  2. git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix
  3. cd pytorch-CycleGAN-and-pix2pix
  4. conda env create -f environment.yml #创建conda环境
  5. 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,用法如下:

  1. pip install visdom
  2. python -m visdom.server
  3. ##如果Error: Address already in use.
  4. lsof -i tcp:8097
  5. kill -9 xxx #xxx被占用的pid号码
  6. lsof -i tcp:8097
  7. 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文件夹压缩包见我发布的资源。

  1. <!--
  2. Copyright 2017-present, Facebook, Inc.
  3. All rights reserved.
  4. This source code is licensed under the license found in the
  5. LICENSE file in the root directory of this source tree.
  6. -->
  7. <!doctype html>
  8. <html>
  9. <head>
  10. <meta charset="utf-8" />
  11. <meta name="viewport" content="width=device-width, initial-scale=1">
  12. <link rel="shortcut icon" href="favicon.png">
  13. <!-- Bootstrap & jQuery -->
  14. <link rel="stylesheet" href={{ static_url("css/bootstrap.min.css") }}>
  15. <script src={{ static_url("js/jquery.min.js") }}></script>
  16. <script src={{ static_url("js/bootstrap.min.js") }}></script>
  17. <link rel="stylesheet" href={{ static_url("css/react-resizable-styles.css") }}>
  18. <link rel="stylesheet" href={{ static_url("css/react-grid-layout-styles.css") }}>
  19. <!-- Other deps -->
  20. <script src={{ static_url("js/react-react.min.js") }}></script>
  21. <script src={{ static_url("js/react-dom.min.js") }}></script>
  22. <script src={{ static_url("fonts/layout_bin_packer") }}></script>
  23. <!-- Mathjax -->
  24. <script type="text/javascript" async src={{ static_url("js/mathjax-MathJax.js") }}></script>
  25. <!-- Plotly -->
  26. <script src={{ static_url("js/plotly-plotly.min.js") }}></script>
  27. <!-- Custom styles for this template -->
  28. <script>
  29. // TODO: this is not great. Should probably be an endpoint with a JSON
  30. // response or the first thing the socket sends back.
  31. var ENV_LIST = [
  32. {% for item in items %}
  33. '{{escape(item)}}',
  34. {% end %}
  35. ];
  36. var ACTIVE_ENV = '{{escape(active_item)}}';
  37. var USER = '{{escape(user)}}';
  38. // Plotly setup
  39. window.PLOTLYENV = window.PLOTLYENV || {};
  40. window.PLOTLYENV.BASE_URL = 'https://plot.ly';
  41. </script>
  42. <script src={{ static_url("js/main.js") }}></script>
  43. <link rel="stylesheet" href={{ static_url("css/style.css") }}>
  44. <title>visdom</title>
  45. <!-- <link rel="icon" href="http://example.com/favicon.png"> -->
  46. </head>
  47. <body>
  48. <noscript>JS is required</noscript>
  49. <div id="app"></div>
  50. </body>
  51. </html>

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

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

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

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

4.test测试

  1. #!./scripts/test_cyclegan.sh
  2. 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代码修改不同:

  1. load_filename='%s_net_%s' %(epoch,name) #test
  2. load_filename='%s_net_%s_B' %(epoch,name) #apply:day2night
  3. 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'。

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/908028
推荐阅读
相关标签
  

闽ICP备14008679号