训练与测试CycleGAN

使用cycle进行数据集的风格转换,也即数据集的domain transferring ,使用的代码地址:https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix

训练过程

按照README进行代码的下载,环境搭建,数据集准备,没有什么大问题,这里略过 接下来以gta到cityscapes为例进行说明:

训练脚本:

python train.py --dataroot 准备的数据集的跟目录 --name sim2cs --load_size 1024 --crop_size 400 --preprocess scale_width_and_crop --lambda_identity 1 --n_epochs 40 --n_epochs_decay 40 

参数说明:
--name 代表训练的名称 这里使用的是 sim2cs
--preprocess 预处理方式

由于其他原因中断,继续训练的脚本,在原来的脚本后面加 参数 --continue_train --epoch_count 47,其中 epoch_count为继续训练开始的epoch数 训练结束后,会在checkpoints文件夹生成 sim2cs的一系列的checkpoint以及latest的模型。

测试过程

测试过程可以使用--model 为 cycle_gan或者是 test ,这里使用的是test,更方便数据集的生成。 需要注意的是: --model 为test的时候加载的latest_net_G.pth,而不是在训练的过程中的latest_net_G_A.pth或者是latest_net_G_B.pth,因此,需要将latest_net_G_A/B.pth重命名为latest_net_G.pth进行A-->B或者是B-->A的图像生成。

这里为了方便,我在checkpoints文件夹下面分别建立了sim10k2cs和cs2sim10k来分别存储各自的latest_net_G.pth,分别重命名自 latest_net_G_A.pth和latest_net_G_B.pth。

至此,sim2cs的test脚本,从gta生成的cityscapes的脚本如下:

python test.py --dataroot 准备数据集的root/testA --model test --name sim10k2cs --process none --dataset_mode single --no_drop

从cs2sim,从cityscapes生成gta的脚本如下:

python test.py --dataroot 准备数据集的root/testB --model test --name cs2sim10k --process none --dataset_mode single --no_drop 

因为需要生成与原图片一样大小的图片,这里--preprocess的参数为none,表示输入图像不进行resize等处理。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章