Skip to content

MingtaoGuo/Face-Attribute-Editing-StyleGAN3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face-Attribute-Editing-StyleGAN3

Face-Attribute-Editing-Encoder4Editing-Text2StyleGAN-InterfaceGAN-GANSpace-Based-on-StyleGAN3

Description


This repo is mainly to re-implement the follow face-editing papers based on stylegan

Getting Started

Prerequisites

  • Linux or macOS
  • NVIDIA GPU + CUDA CuDNN
  • Python 3

Installation

  • 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 in environment.yaml.

Inference e4e

python e4e_inference.py --img_path resources/imgs/1.png --pretrain saved_models/13_12500_pspEncoder.pth
Image
Inverse

Train e4e

  • 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

Inference Text2StyleGAN

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

Inference InterfaceGAN

python interfacegan_edit.py --stylegan stylegan3-t-ffhq-1024x1024.pkl --boundary resources/interfacegan/boundary_glasses.pth
--------glasses--------- ---------beard--------- ---------young--------- ---------smile---------

Train InterfaceGAN

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

Inference GANSpace

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)

Author

Mingtao Guo E-mail: gmt798714378 at hotmail dot com

Reference

[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.

About

Face editing by e4e, text2stylegan,interfacegan,ganspace

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published