Face-Attribute-Editing-Encoder4Editing-Text2StyleGAN-InterfaceGAN-GANSpace-Based-on-StyleGAN3
This repo is mainly to re-implement the follow face-editing papers based on stylegan
- Encoder4Editing: Designing an Encoder for StyleGAN Image Manipulation
- InterfaceGAN: InterFaceGAN: Interpreting the Disentangled Face Representation Learned by GANs
- GANSpace: GANSpace: Discovering Interpretable GAN Controls
- Linux or macOS
- NVIDIA GPU + CUDA CuDNN
- Python 3
- Clone the repository:
git clone https://github.com/MingtaoGuo/Face-Attribute-Editing-StyleGAN3.git
cd Face-Attribute-Editing-StyleGAN3
wget https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-t-ffhq-1024x1024.pkl
- Dependencies:
We recommend running this repository using Anaconda. All dependencies for defining the environment are provided inenvironment.yaml
.
- Download the e4e pretrained model FFHQ-e4e-stylegan3
python e4e_inference.py --img_path resources/imgs/1.png --pretrain saved_models/13_12500_pspEncoder.pth
Image | ![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
Inverse | ![]() |
![]() |
![]() |
![]() |
- Download the FFHQ dataset from NVlabs
- Download the face recognition model arcface from insightface Go to Baidu Drive -> arcface_torch -> glint360k_cosface_r50_fp16_0.1 -> backbone.pth
python e4e_train.py --data_path FFHQ --batch_size 4 --epoch 20 --arcface saved_models/backbone.pth
python text2stylegan.py --text "a woman with blue eyes" --opt_space w --learning_rate 0.02
Description | an european woman with blue eyes | an old asian man with gray hair | an asian woman with black long straight hair | a woman with blond hair is smiling |
---|---|---|---|---|
Text2img | ![]() |
![]() |
![]() |
![]() |
python interfacegan_edit.py --stylegan stylegan3-t-ffhq-1024x1024.pkl --boundary resources/interfacegan/boundary_glasses.pth
![]() |
![]() |
![]() |
![]() |
---|---|---|---|
--------glasses--------- | ---------beard--------- | ---------young--------- | ---------smile--------- |
![]() |
![]() |
![]() |
![]() |
We use a vision-language model CLIP as face attribute classifier to predict generated face images from StyleGAN.
python interfacegan_gendata.py --n_samples 200000 --stylegan stylegan3-t-ffhq-1024x1024.pkl
python interfacegan_predict_attr.py --attr_text glasses
python interfacegan_linear_svm.py --path_txt resources/interfacegan/glasses_label.txt --boundary_save resources/interfacegan/boundary_glasses.pth
python ganspace.py --stylegan stylegan3-t-ffhq-1024x1024.pkl --v_idxs 0 --layer_idxs 0-18 --n_samples 10000
v_0, layer_1_18 (gender) |
---|
![]() |
v_1, layer_1_18 (rotate) |
---|
![]() |
v_2, layer_1_18 (rotate + age+ bkg) |
---|
![]() |
Mingtao Guo E-mail: gmt798714378 at hotmail dot com
[1]. Tov, Omer, et al. "Designing an encoder for stylegan image manipulation." ACM Transactions on Graphics (TOG) 40.4 (2021): 1-14.
[2]. Shen, Yujun, et al. "Interfacegan: Interpreting the disentangled face representation learned by gans." IEEE transactions on pattern analysis and machine intelligence (2020).
[3]. Härkönen, Erik, et al. "Ganspace: Discovering interpretable gan controls." Advances in Neural Information Processing Systems 33 (2020): 9841-9850.
[4]. Radford, Alec, et al. "Learning transferable visual models from natural language supervision." International Conference on Machine Learning. PMLR, 2021.