1 Star 0 Fork 1

Mike_W / ConSinGAN

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ConSinGAN

正式实施由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的新技术。 我们的模型在原始训练图像的几个不同分辨率上进行迭代训练,其中分辨率随着训练的进行而增加。 每当我们提高训练图像的分辨率时,我们也通过添加额外的卷积层来增加生成器的容量。 在给定的时间内,我们不训练完整的模型,而只训练它的部分,即最近添加的卷积层。 最新的卷积层以给定的学习率进行训练,而以前的卷积层则以较小的学习率进行训练。

Model-Architecture

Installation

  • python 3.5
  • pytorch 1.1.0
pip install -r requirements.txt

Unconditional Generation无条件生成

要使用我们的文献运行中的默认参数训练模型,请执行以下操作:

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图像中的差异:

Learning Rate Scaling Visualization学习率缩放可视化

要修改学习速率缩放运行:

python main_train.py --gpu 0 --train_mode generation --input_name Images/Generation/colusseum.jpg --lr_scale 0.5

更多阶段的培训有助于展示应保持不变的大型全球结构的图像,如: Trained Stages Visualization训练阶段可视化

要修改运行的训练阶段数:

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

Retargeting Visualization重定目标可视化

#协调
要训练除训练图像外不使用任何内容的默认协调模型,请执行以下操作:

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分钟。

Harmonization Visualization协调可视化

#编辑
编辑任务的训练与协调任务的训练相同,只是我们在更多的阶段进行训练,并且使用稍微不同的图像增强技术,在每次迭代时交换训练图像中的随机面片。

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

Editing Visualization编辑可视化

Additional Data附加数据

“用户研究”文件夹包含我们用于进行用户研究的原始图像。

Acknowledgements致谢

Our implementation is based on this implementation of the SinGAN paper.

Citation

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}
}
MIT License Copyright (c) 2020 Tobias Hinz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

单图像GANs训练技术 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/Mike_W/ConSinGAN.git
git@gitee.com:Mike_W/ConSinGAN.git
Mike_W
ConSinGAN
ConSinGAN
master

搜索帮助