Clone this repo and install dependencies via pip install requirements.txt
.
run
python download.py
Pretrained models
- StyleGAN2 (ffhq, afhqcat, afhqdog, cars, horses, churches)
- Finetuned StyleGAN2 models (ffhq -> afhqcat, ffhq -> afhqdog, ffhq -> metfaces, ffhq -> mega)
- Pretrained StyleSpace directions (StyleSpace directions based on DiFa and StyleGAN-NADA models)
Training launches by following command
python main.py exp.config={config_name}
configs are stored in configs
dir
4 model types are implemented in trainers.py, see the file to get details.
- Available methods:
- MindTheGap (configs/im2im_mtg.yaml)
- DiFa (configs/im2im_difa.yaml)
- JoJoGAN (configs/im2im_jojo.yaml)
- StyleGAN-NADA (configs/td_single_ffhq.yaml)
Ensure config settings to launch training with appropriate setup:
config_dir
: configsconfig
: config_name.yamlproject
:WandbProjectName
tags
:- tag1
- tag2
name
:WandbRunName
seed
: 0root
: ./notes
: empty notesstep_save
: 20 – model dump frequencytrainer
: trainer_namemodels_root
: (used this folder as root for experiments when specified)
iter_num
: 300 – number of training iterationsbatch_size
: 4device
: cuda:0generator
: stylegan2patch_key
: cin_mult (see core/parametrizations.py)phase
: mapping – StyleGAN2 part which is fine-tuned, only used whenpatch_key
=original
source_class
: Photo – description of source domaintarget_class
: 3D Render in the Style of Pixar – description of target domain (in case of im2im setup image path is required)auto_layer_k
: 16auto_layer_iters
: 0 – number of iterations for adaptive corresponding stylegan2 layer freezeauto_layer_batch
: 8mixing_noise
: 0.9
visual_encoders
: – clip encoders that are used for clip based losses- ViT-B/32
- ViT-B/16
loss_funcs
:- loss_name1
- loss_name2
- ...
loss_coefs
:- loss_coef1
- loss_coef2
- ...
g_reg_every
: 4 – stylegan2 regularization coefficient (not recommended to change)optimizer
:weight_decay
: 0.0lr
: 0.02betas
:- 0.9
- 0.999
log_every
: 10 – loss logging steplog_images
: 20 – images logging steptruncation
: 0.7 – truncation during images loggingnum_grid_outputs
: 1 – number of logging grids
When training ends model checkpoints could be found in local_logged_exps/
. Each ckpt_name.pt
could be inferenced using a helper classes Inferencer
in core/utils/example_utils.py
.
Pretrained models for various stylization are provided.
Please refer to download.py
and run python download.py ckpt
from repository root.
Each notebook is depend on pretrained models from download.py
- examples/multiple_morping.ipynb
- examples/combined_morphing.ipynb
- examples/adaptation_in_finetuned_gan.ipynb
- examples/editing.ipynb
- examples/pruned_forward.ipynb
StyleGAN2 implementation:
https://github.com/rosinality/stylegan2-pytorch
License (MIT) https://github.com/rosinality/stylegan2-pytorch/blob/master/LICENSE
Encoders implementation https://github.com/yuval-alaluf/restyle-encoder License (MIT) https://github.com/yuval-alaluf/restyle-encoder/blob/main/LICENSE
StyleFlow implementation https://github.com/RameenAbdal/StyleFlow/tree/master License CC BY-NC-SA 4.0
LPIPS implementation:
https://github.com/S-aiueo32/lpips-pytorch
License (BSD 2-Clause) https://github.com/S-aiueo32/lpips-pytorch/blob/master/LICENSE
Please Note: The CUDA files under the StyleGAN2 ops directory are made available under the Nvidia Source Code License-NC