## Simple StyleGan2 for Pytorch
[![PyPI version](https://badge.fury.io/py/stylegan2-pytorch.svg)](https://badge.fury.io/py/stylegan2-pytorch)
Simple working Pytorch implementation of Stylegan2 based on https://arxiv.org/abs/1912.04958
Below are some flowers that do not exist.
<img src="https://raw.githubusercontent.com/lucidrains/stylegan2-pytorch/master/samples/flowers.jpg" width="450" height="auto">
Neither do these hands
<img src="https://raw.githubusercontent.com/lucidrains/stylegan2-pytorch/master/samples/hands.jpg" width="450" height="auto">
## Install
You will need a machine with a GPU and CUDA installed. Then pip install the package like so
```bash
$ pip install stylegan2_pytorch
```
If you are using a windows machine, the following commands reportedly works.
```bash
$ conda install pytorch torchvision -c python
$ pip install stylegan2_pytorch
```
## Use
```bash
$ stylegan2_pytorch --data /path/to/images
```
That's it. Sample images will be saved to `results/default` and models will be saved periodically to `models/default`.
## Advanced Use
You can specify the name of your project with
```bash
$ stylegan2_pytorch --data /path/to/images --name my-project-name
```
You can also specify the location where intermediate results and model checkpoints should be stored with
```bash
$ stylegan2_pytorch --data /path/to/images --name my-project-name --results_dir /path/to/results/dir --models_dir /path/to/models/dir
```
By default, if the training gets cut off, it will automatically resume from the last checkpointed file. If you want to restart with new settings, just add a `new` flag
```bash
$ stylegan2_pytorch --new --data /path/to/images --name my-project-name --image-size 512 --batch-size 1 --gradient-accumulate-every 16 --network-capacity 10
```
Once you have finished training, you can generate images from your latest checkpoint like so.
```bash
$ stylegan2_pytorch --generate
```
If a previous checkpoint contained a better generator, (which often happens as generators start degrading towards the end of training), you can load from a previous checkpoint with another flag
```bash
$ stylegan2_pytorch --generate --load-from {checkpoint number}
```
## Memory considerations
The more GPU memory you have, the bigger and better the image generation will be. Nvidia recommended having up to 16GB for training 1024x1024 images. If you have less than that, there are a couple settings you can play with so that the model fits.
```bash
$ stylegan2_pytorch --data /path/to/data \
--batch-size 3 \
--gradient-accumulate-every 5 \
--network-capacity 16
```
1. Batch size - You can decrease the `batch-size` down to 1, but you should increase the `gradient-accumulate-every` correspondingly so that the mini-batch the network sees is not too small. This may be confusing to a layperson, so I'll think about how I would automate the choice of `gradient-accumulate-every` going forward.
2. Network capacity - You can decrease the neural network capacity to lessen the memory requirements. Just be aware that this has been shown to degrade generation performance.
## Todo
1. Add mixed precision and multi-GPU support
## Appreciation
Thank you to Matthew Mann for his inspiring [simple port](https://github.com/manicman1999/StyleGAN2-Tensorflow-2.0) for Tensorflow 2.0
This also uses the `hinge L∞ gradient penalty` described in https://arxiv.org/abs/1910.06922
## References
```bibtex
@article{Karras2019stylegan2,
title = {Analyzing and Improving the Image Quality of {StyleGAN}},
author = {Tero Karras and Samuli Laine and Miika Aittala and Janne Hellsten and Jaakko Lehtinen and Timo Aila},
journal = {CoRR},
volume = {abs/1912.04958},
year = {2019},
}
```
```bibtex
@article{jolicoeur2019connections}
title={Connections between Support Vector Machines, Wasserstein distance and gradient-penalty GANs},
author={Jolicoeur-Martineau, Alexia},
journal={arXiv preprint arXiv:1910.06922},
year={2019}
}
```
```bibtex
@article{,
title= {Oxford 102 Flowers},
author= {Nilsback, M-E. and Zisserman, A., 2008},
abstract= {A 102 category dataset consisting of 102 flower categories, commonly occuring in the United Kingdom. Each class consists of 40 to 258 images. The images have large scale, pose and light variations.}
}
```
```bibtex
@article{afifi201911k,
title={11K Hands: gender recognition and biometric identification using a large dataset of hand images},
author={Afifi, Mahmoud},
journal={Multimedia Tools and Applications},
volume={78},
number={15},
pages={20835--20854},
year={2019},
publisher={Springer}
}
```
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共12个文件
txt:4个
py:3个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:stylegan2_pytorch-0.4.10.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
stylegan2_pytorch-0.4.10.tar.gz (12个子文件)
stylegan2_pytorch-0.4.10
PKG-INFO 584B
bin
stylegan2_pytorch 1KB
stylegan2_pytorch.egg-info
PKG-INFO 584B
requires.txt 57B
SOURCES.txt 323B
top_level.txt 18B
dependency_links.txt 1B
stylegan2_pytorch
__init__.py 66B
stylegan2_pytorch.py 23KB
setup.cfg 79B
setup.py 843B
README.md 5KB
共 12 条
- 1
资源评论
- 2201_757240302024-03-26感谢大佬,让我及时解决了当下的问题,解燃眉之急,必须支持!
挣扎的蓝藻
- 粉丝: 12w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功