项目作者: dmitry-vorobiev

项目描述 :
my playground for generative modeling
高级语言: Python
项目地址: git://github.com/dmitry-vorobiev/generative-models.git
创建时间: 2020-04-08T09:35:19Z
项目社区:https://github.com/dmitry-vorobiev/generative-models

开源协议:Apache License 2.0

下载


Generative models

My playground for generative modeling.

Models:

Requirements

The code was developed and tested under the environment:

  • OS: Ubuntu 18.04.4 LTS (5.0.0-37-generic)
  • CUDA 10.1.243
  • NVIDIA’s drivers 435.21
  • Conda 4.8.3
  • Python 3.7.7
  • PyTorch 1.4.0

Installation

```shell script
pip install -r requirements.txt

  1. ## Configuration
  2. Almost all configuration is made using [Hydra framework](https://github.com/facebookresearch/hydra)
  3. from Facebook Research.
  4. To change various settings you can either edit *.yaml* files
  5. in the `config` folder or pass corresponding params to the command line.
  6. The second option is useful for quick testing.
  7. For more information about configuration options available please visit [Hydra docs](https://hydra.cc/).
  8. ### Dataset
  9. To point the train script to your local data folder update `data.root` setting in the `config/train_gan.yaml`
  10. or pass it as a command line argument:
  11. ```shell script
  12. python src/train_gan.py data.root=/path/to/local/dir

Model

The are a few predefined model presets available. You can find them in the config/model folder.
Update defaults.model entry in the config/train_gan.yaml
or pass model arg with a name of preset you want to use:

```shell script
python src/train_gan.py model=stylegan2/config_f

  1. Don't forget to change model resolution `model.*.params.img_res` and
  2. number of classes `model.*.params.num_classes` according to your dataset.
  3. ## Usage
  4. ### Generate images
  5. #### Random images
  6. Use `sample.mode=random` to generate randomly sampled images.
  7. `out.cols` and `out.rows` can be used
  8. to save many images as an image grid in a single file. If both set to 1, each image will be saved in it's own file.
  9. ```shell script
  10. python src/generate_images.py model=stylegan2/config_f sample.mode=random sample.num_images=100 \
  11. model.G.weights=/path/to/model/state_dict \
  12. out.dir=/path/to/save/dir

Style mixing

Change sample.mode to style-mixing.
Use out.cols and out.rows to specify the number of images to mix.
This will produce (rows x cols) mixed images along with (rows + cols) original images, used
as a source for style mixing.
sample.num_images setting will be ignored (subject to change).

```shell script
python src/generate_images.py model=stylegan2/config_f sample.mode=’style-mixing’ \
out.cols=8 out.rows=3 \
model.G.weights=/path/to/model/state_dict \
out.dir=/path/to/save/dir

  1. You can find other settings in `config/generate_images.yaml`.
  2. ### Multi-GPU training
  3. Launch distributed training on GPUs:
  4. ```shell script
  5. python -m torch.distributed.launch --nproc_per_node=2 --use_env src/train_gan.py

It’s important to run torch.distributed.launch with --use_env,
otherwise hydra will yell
at you for passing unrecognized arguments.

License

Some parts of this work are derivatives and as such they are licensed
under the same license terms as the original work. See corresponding README.md
for details:

Citation

  1. @article{Karras2019stylegan2,
  2. title = {Analyzing and Improving the Image Quality of {StyleGAN}},
  3. author = {Tero Karras and Samuli Laine and Miika Aittala and Janne Hellsten and Jaakko Lehtinen and Timo Aila},
  4. journal = {CoRR},
  5. volume = {abs/1912.04958},
  6. year = {2019},
  7. }