Awesome
AdvStyle - Official PyTorch Implementation
<img src='img/teaser.png' >Discovering Interpretable Latent Space Directions of GANs Beyond Binary Attributes.
Huiting Yang, Liangyu Chai, Qiang Wen, Shuang Zhao, Zixun Sun, Shengfeng He
In CVPR 2021
Prerequisites
- Linux
- Python 3
- NVIDIA GPU + CUDA CuDNN
Setup
- Clone this repo:
git clone https://github.com/BERYLSHEEP/AdvStyle.git
- Download resources:
- Please download the pretrained FFHQ StyleGAN and anime StyleGAN weights
- Move the weights to
models/pretrain/pytorch
Testing Demo
The following commands are examples of testing the learned direction:
# stylegan ffhq
python new_demo.py manipulate_test supermodel \
--gan_model stylegan_ffhq --resolution 1024 --latent_type z
# stylegan anime
python new_demo.py manipulate_test maruko \
--gan_model stylegan_anime --resolution 512 --latent_type z
if you want to manipulate multi attributes simultaneously, you can list all the attributes on the command as follow:
# multi attribute manipulation
python new_demo.py manipulate_test blonde,open_mouth \
--gan_model stylegan_anime --resolution 512 --latent_type z
If you want to specific the manipulated latent code, you can set the --noise_path option:
# specific latent code
python new_demo.py manipulate_test maruko \
--gan_model stylegan_anime --resolution 512 --latent_type z \
--noise_path ./noise/maruko/2.npy
Results are saved to result/{attribute}
The attribute names are the file names in the boundaries
directory.
Interactive Demo
<img src="img/app.png">-
Prerequisites: Flask
pip install flask pip install --upgrade flask_nav pip install --upgrade flask_bootstrap
-
Running
# only for stylegan_anime # the input latent code is belong to latent space z [1, 512] python app.py --latent_code noise/maruko/16.npy --composing_type z # the input latent code is belong to latent space w+ [1, 16, 512] python app.py --latent_code noise/38_w+.npy --composint_type w+
-
Instructions
- Only one attribute can be edited at once time.
- Multi attributes edit examples:
- Click the corresponding
Edit
Button for "Pink Hair", then move the corresponding toolbar to the desired step. - Click the corresponding
Edit
Button for "Open Mouth", then move the corresponding toolbar to the desired step. - ....
- Click the corresponding
Related Project
- The pretrained StyleGAN weights are from official StyleGAN and Gwern
- Using the pytorch implementation of StyleGAN from [InterFaceGAN](Pytorch implementation of official model)
Citation
If you use this code for your research, please cite our paper:
@InProceedings{Yang_2021_CVPR,
author = {Yang, Huiting and Chai, Liangyu and Wen, Qiang and Zhao, Shuang and Sun, Zixun and He, Shengfeng},
title = {Discovering Interpretable Latent Space Directions of GANs Beyond Binary Attributes},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {June},
year = {2021},
pages = {12177-12185}
}