背景:
源码作者:junyanz/pytorch-CycleGAN-and-pix2pix
源码地址:https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix
参考:https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix
目录
一、下载
1.1 下载
git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix
cd pytorch-CycleGAN-and-pix2pix
1.2 安装好依赖项
PyTorch安装,见:https://blog.csdn.net/weixin_36474809/article/details/88715360
Install [PyTorch](http://pytorch.org and) 0.4+ and other dependencies (e.g., torchvision, visdom and dominate).
- For pip users, please type the command
pip install -r requirements.txt
但是对于我们而言,因为之前装好的python在env/bin/python,所以我们需要在上级文件夹输入
env/bin/python -m pip install -r pytorch-CycleGAN-and-pix2pix/requirements.txt
二、训练与测试
2.1 下载数据集
我们以map数据集为例子。
对我们而言,出现问题
[xingxiangrui@yq01-gpu-yq-face-21-5 pytorch-CycleGAN-and-pix2pix]$ bash ./datasets/download_cyclegan_dataset.sh maps
Specified [maps]
WARNING: timestamping does nothing in combination with -O. See the manual
for details.
--2019-03-22 11:07:20-- https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/maps.zip
Resolving people.eecs.berkeley.edu... 128.32.189.73
Connecting to people.eecs.berkeley.edu|128.32.189.73|:443... connected.
ERROR: certificate common name "iris.eecs.berkeley.edu" doesn't match requested host name "people.eecs.berkeley.edu".
To connect to people.eecs.berkeley.edu insecurely, use '--no-check-certificate'.
mkdir: cannot create directory './datasets/maps/': File exists
Archive: ./datasets/maps.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of ./datasets/maps.zip or
./datasets/maps.zip.zip, and cannot find ./datasets/maps.zip.ZIP, period.
其他所有数据集均无法下载:例如下面网页之中apple2orange和horse2zebra等等
https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/docs/datasets.md
数据集的下载出现问题,所以我们只好自备数据集。
2.2. 自备数据集
作者有给出一个自制模型和数据集的方法:
准备一个文件夹try,里面包含四个文件夹trainA、trainB、testA、testB,每个文件夹内分别放有若干图片
复制到 pytorch-CycleGAN-and-pix2pix/datasets/ 下
2.3 可视化
可视化用的是visdom.server
To view training results and loss plots, run python -m visdom.server
and click the URL http://localhost:8097
关于visdom.server的用法我们暂时还没确定清楚
2.4 训练
#!./scripts/train_cyclegan.sh
python train.py --dataroot ./datasets/maps --name maps_cyclegan --model cycle_gan
可以看出其中
- --dataroot 训练数据的根目录
- --name 训练模型的名称
- --model 训练的模型的类型
更多训练时的信息查看 ./checkpoints/maps_cyclegan/web/index.html
2.5 测试
#!./scripts/test_cyclegan.sh
python test.py --dataroot ./datasets/maps --name maps_cyclegan --model cycle_gan
测试结果存于 ./results/maps_cyclegan/latest_test/index.html
三、预训练模型
3.1 预训练模型
- You can download a pretrained model (e.g. horse2zebra) with the following script:
bash ./scripts/download_cyclegan_model.sh horse2zebra
- The pretrained model is saved at
./checkpoints/{name}_pretrained/latest_net_G.pth
. Check here for all the available CycleGAN models.
3.2 数据集
- To test the model, you also need to download the horse2zebra dataset:
bash ./datasets/download_cyclegan_dataset.sh horse2zebra
- Then generate the results using
python test.py --dataroot datasets/horse2zebra/testA --name horse2zebra_pretrained --model test --no_dropout
-
The option
--model test
is used for generating results of CycleGAN 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. -
For your own experiments, you might want to specify
--netG
,--norm
,--no_dropout
to match the generator architecture of the trained model.
四、docker
https://baike.baidu.com/item/Docker/13344470?fr=aladdin
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/docs/docker.md