正式实施由Tobias Hinz、Matthew Fisher、Oliver Wang和Stefan Wermter撰写的论文“改进的单图像GANs训练技术””(https://arxiv.org/abs/2003.11512)。 关于本文的简短摘要,请参阅我们的[博客文章](https://www.tobiasinz.com/2020/03/24/improved techniques For training single image gans.html)。 我们研究并推荐在单个图像上训练GANs的新技术。 我们的模型在原始训练图像的几个不同分辨率上进行迭代训练,其中分辨率随着训练的进行而增加。 每当我们提高训练图像的分辨率时,我们也通过添加额外的卷积层来增加生成器的容量。 在给定的时间内,我们不训练完整的模型,而只训练它的部分,即最近添加的卷积层。 最新的卷积层以给定的学习率进行训练,而以前的卷积层则以较小的学习率进行训练。
pip install -r requirements.txt
要使用我们的文献运行中的默认参数训练模型,请执行以下操作:
python main_train.py --gpu 0 --train_mode generation --input_name Images/Generation/angkorwat.jpg
在NVIDIA GeForce GTX 1080Ti上训练一个模型需要大约20-25分钟。
###修改学习率缩放和训练阶段数
为了影响样本多样性和图像质量,我们建议使用学习率缩放(默认值为“0.1”)和训练阶段数(默认值为“6”)。
如果图像更复杂(使用更高的学习速率缩放)或您希望在分辨率更高的图像上进行训练(使用更多阶段),这将特别有用。
例如,增加学习率缩放将意味着较低阶段的训练具有较高的学习率,因此可以学习更忠实的原始图像模型。
例如,如果使用“0.1”或“0.5”的学习率刻度对模型进行训练,则观察生成的Colusseum图像中的差异:
要修改学习速率缩放运行:
python main_train.py --gpu 0 --train_mode generation --input_name Images/Generation/colusseum.jpg --lr_scale 0.5
更多阶段的培训有助于展示应保持不变的大型全球结构的图像,如:
要修改运行的训练阶段数:
python main_train.py --gpu 0 --train_mode generation --input_name Images/Generation/colusseum.jpg --train_stages 7
###结果
输出保存到“TrainedModels/”并用Tensorboard记录培训过程。
可视化图像网格中的左上角图像是原始训练图像,所有其他图像都是生成的图像。
要监视进度,请转到相应的文件夹并运行
tensorboard --logdir .
###采样更多图像
要从经过训练的模型运行中采样更多图像,请执行以下操作:
python evaluate_model.py --gpu 0 --model_dir TrainedModels/colusseum/.../ --num_samples 50
This will use the model to generate num_samples
images in the default as well as scaled resolutions.
The results will be saved in a folder Evaluation
in the model_dir
.
###无条件生成(任意大小)
默认的无条件图像生成也适用于在生成图像的边缘诱导多样性。
当生成任意大小(特别是较大)的图像时,这通常会破坏图像布局。
因此,我们还提供了一个选项,当我们希望使用模型生成任意大小的图像时,我们可以稍微更改上采样和噪声添加以提高结果。
训练、模型结构、损失函数等保持不变,唯一的变化是在不同的发电机级之间添加随机噪声和略有不同的上采样程序。
要训练更适合生成任意大小图像的模型,请运行:
python main_train.py --gpu 0 --train_mode retarget --input_name Images/Generation/colusseum.jpg
#协调
要训练除训练图像外不使用任何内容的默认协调模型,请执行以下操作:
python main_train.py --gpu 0 --train_mode harmonization --train_stages 3 --min_size 120 --lrelu_alpha 0.3 --niter 1000 --batch_norm --input_name Images/Harmonization/scream.jpg
三个阶段的训练大约需要5-10分钟。减小“最小尺寸”可加快训练速度,增加“最小尺寸”可获得更好的效果。
要使给定图像与预先训练的模型协调:
python evaluate_model.py --gpu 0 --model_dir TrainedModels/scream/.../ --naive_img Images/Harmonization/scream_naive.jpg
如果您已经有了要用于监视进度的原始图像(原始图像仅在测试时使用,而不是在训练时使用):
python main_train.py --gpu 0 --train_mode harmonization --train_stages 3 --min_size 120 --lrelu_alpha 0.3 --niter 1000 --batch_norm --input_name Images/Harmonization/pencil_tree.jpg --naive_img Images/Harmonization/pencil_tree_naive.jpg
要在给定图像上微调预先训练的模型(在训练时也使用原始图像):
python main_train.py --gpu 0 --train_mode harmonization --input_name Images/Harmonization/pencil_tree.jpg --naive_img Images/Harmonization/pencil_tree_naive.jpg --fine_tune --model_dir TrainedModels/pencil_tree/...
根据模型和图像大小,对模型进行微调培训应花费1-5分钟。
#编辑
编辑任务的训练与协调任务的训练相同,只是我们在更多的阶段进行训练,并且使用稍微不同的图像增强技术,在每次迭代时交换训练图像中的随机面片。
python main_train.py --gpu 0 --train_mode editing --batch_norm --niter 1000 --input_name Images/Editing/stone.png
或者,如果应该使用天真的图像来监视训练进度(但不是训练本身):
python main_train.py --gpu 0 --train_mode editing --batch_norm --niter 1000 --input_name Images/Editing/stone.png --naive_img Images/Editing/stone_edit_1.png
要微调模型:
python main_train.py --gpu 0 --input_name Images/Editing/stone.png --naive_img Images/Editing/stone_edit_1.png --fine_tune --model_dir TrainedModels/stone/...
To evaluate评估:
python evaluate_model.py --gpu 0 --model_dir TrainedModels/stone/.../ --naive_img Images/Harmonization/stone_edit_1.png
“用户研究”文件夹包含我们用于进行用户研究的原始图像。
Our implementation is based on this implementation of the SinGAN paper.
If you found this code useful please consider citing:
@article{hinz2020improved,
title={Improved Techniques for Training Single-Image GANs},
author={Tobias Hinz, Matthew Fisher, Oliver Wang, and Stefan Wermter},
journal={arXiv preprint arXiv:2003.11512},
year={2020}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。