cycleGAN的使用

github地址

数据准备

需要一个root_dir,下面有trainA,trainB两个文件夹
只运行训练py文件可以不需要testA,testB

git clone 从官方原文github克隆到本地来

git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix
cd pytorch-CycleGAN-and-pix2pix

安装依赖

For pip users, please type the command pip install -r requirements.txt
For Conda users, you can create a new Conda environment using conda env create -f environment.yml

更改参数

pycharm - run - edit cofiguration
用pycharm打开后更改train.py输入参数
dataroot:你的root_dir地址
name:本次训练项目名称,会在checkpoint文件夹下保存
model:用的模型,默认cycle_gan

--dataroot your_dir --name RIN_ct_to_mr_cyclegan --model cycle_gan

其他参数可在option文件夹下三个py文件按需更改
这两个加起来是总的训练轮数(上面是初始学习率训练几轮,下面是递减几轮)

可视化设置

conda进入虚拟环境pytorch-CycleGAN-and-pix2pix
python -m visdom.server
如果出现端口占用:
执行命令:netstat -tunlp
然后找到占用8097端口的PID kill -9 PID
完成后出现You can navigate to http://localhost:8097
一直保持这个终端处于开启状态

训练

运行train.py

测试

源代码给了两种测试方法

Example (You need to train models first or download pre-trained models from our website):
    Test a CycleGAN model (both sides):
        python test.py --dataroot ./datasets/maps --name maps_cyclegan --model cycle_gan

    Test a CycleGAN model (one side only):
        python test.py --dataroot datasets/horse2zebra/testA --name horse2zebra_pretrained --model test --no_dropout

    The option '--model test' is used for generating CycleGAN results only for one side.
    This option will automatically set '--dataset_mode single', which only loads the images from one set.
    On the contrary, using '--model cycle_gan' requires loading and generating results in both directions,
    which is sometimes unnecessary. The results will be saved at ./results/.
    Use '--results_dir <directory_path_to_save_result>' to specify the results directory.

但是第一种我以为是两边同时生成,GA和GB一起调用,但是经过测试只有一边能生成,both sides意思是反向生成rec和idt
所以用第二种作为测试方法
同样的在pycharm - run - edit cofiguration
更改test文件的初始参数

--dataroot datasets/horse2zebra/testA --name horse2zebra_pretrained --model test --no_dropout

新建一个放模型的文件夹,Ga或者Gb,把模型文件改名为latest_net_G.pth
将name后面参数改为这个文件夹
这样就可以运行测试了,但是注意option里的模型要设置成你的pth文件里的模型,否则报错

本文作者:梅雨明夏

本文链接:https://www.cnblogs.com/xyf9474/p/17005822.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   梅雨明夏  阅读(486)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 一路向北 Jay
  2. 2 七里香 Jay
  3. 3 不爱我就拉倒 Jay
一路向北 - Jay
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

后视镜里的世界

越来越远的道别

你转身向背

侧脸还是很美

我用眼光去追

竟听见你的泪

在车窗外面排徊

是我错失的机会

你站的方位

跟我中间隔着泪

街景一直在后退

你的崩溃在窗外零碎

我一路向北

离开有你的季节

你说你好累

已无法再爱上谁

风在山路吹

过往的画面

全都是我不对

细数惭愧 我伤你几回

☆痴人说梦☆

无与伦比→为杰沉沦

后视镜里的世界

越来越远的道别

你转身向背

侧脸还是很美

我用眼光去追

竟听见你的泪

在车窗外面排徊

是我错失的机会

你站的方位

跟我中间隔着泪

街景一直在后退

你的崩溃在窗外零碎

我一路向北

离开有你的季节

你说你好累

已无法再爱上谁

风在山路吹

过往的画面

全都是我不对

细数惭愧 我伤你几回

我一路向北

离开有你的季节

方向盘周围

回转着我的后悔

我加速超越

却甩不掉紧紧跟随的伤悲

细数惭愧 我伤你几回

停止狼狈 就让错纯粹