by LynnHo

AttGAN Tensorflow, AttGAN: Facial Attribute Editing by Only Changing What You Want

446 Stars 108 Forks Last release: 9 months ago (v1) MIT License 45 Commits 1 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


  • 11 Jan 2020: We clean up the code to make it more readable! The old version is here: v1.


TIP Nov. 2019, arXiv Nov. 2017

TensorFlow implementation of AttGAN: Facial Attribute Editing by Only Changing What You Want.


Exemplar Results

  • See for more results, we try higher resolution and more attributes (all 40 attributes!!!)

  • Inverting 13 attributes respectively

    from left to right: Input, Reconstruction, Bald, Bangs, BlackHair, BlondHair, BrownHair, BushyEyebrows, Eyeglasses, Male, MouthSlightlyOpen, Mustache, NoBeard, PaleSkin, Young


  • Environment

    • Python 3.6
    • TensorFlow 1.15
    • OpenCV, scikit-image, tqdm, oyaml
    • we recommend Anaconda or Miniconda, then you can create the AttGAN environment with commands below

      conda create -n AttGAN python=3.6

      source activate AttGAN

      conda install -c anaconda opencv

      conda install -c anaconda scikit-image

      conda install -c anaconda tqdm

      conda install -c conda-forge oyaml

      conda install -c anaconda tensorflow-gpu=1.15

  • Data Preparation

    • Option 1: CelebA-unaligned (higher quality than the aligned data, 10.2GB)

      • download the dataset

      • unzip and process the data

        7z x ./data/img_celeba/img_celeba.7z/img_celeba.7z.001 -o./data/img_celeba/

        unzip ./data/img_celeba/ -d ./data/img_celeba/

        python ./scripts/

    • Option 2: CelebA-HQ (we use the data from CelebAMask-HQ, 3.2GB)

      • (move to ./data/ Google Drive or Baidu Netdisk
      • unzip and process the data

        unzip ./data/ -d ./data/

        python ./scripts/

  • Run AttGAN

    • NOTICE: if you create a new conda environment, remember to activate it before any command

      source activate AttGAN
    • training (see for more training commands)

      \\ for CelebA
      python \
      --load_size 143 \
      --crop_size 128 \
      --model model_128 \
      --experiment_name AttGAN_128

      \ for CelebA-HQ CUDA_VISIBLE_DEVICES=0
      --img_dir ./data/CelebAMask-HQ/CelebA-HQ-img
      --train_label_path ./data/CelebAMask-HQ/train_label.txt
      --val_label_path ./data/CelebAMask-HQ/val_label.txt
      --load_size 128
      --crop_size 128
      --n_epochs 200
      --epoch_start_decay 100
      --model model_128
      --experiment_name AttGAN_128_CelebA-HQ

    • testing

      • single attribute editing (inversion)

        \\ for CelebA
        python \
        --experiment_name AttGAN_128

        \ for CelebA-HQ CUDA_VISIBLE_DEVICES=0
        --img_dir ./data/CelebAMask-HQ/CelebA-HQ-img
        --test_label_path ./data/CelebAMask-HQ/test_label.txt
        --experiment_name AttGAN_128_CelebA-HQ

      • multiple attribute editing (inversion) example

        \\ for CelebA
        python \
        --test_att_names Bushy_Eyebrows Pale_Skin \
        --experiment_name AttGAN_128
      • attribute sliding example

        \\ for CelebA
        python \
        --test_att_name Pale_Skin \
        --test_int_min -2 \
        --test_int_max 2 \
        --test_int_step 0.5 \
        --experiment_name AttGAN_128
    • loss visualization

      tensorboard \
      --logdir ./output/AttGAN_128/summaries \
      --port 6006
    • convert trained model to .pb file

      python --experiment_name AttGAN_128
  • Using Trained Weights

  • Example for Custom Dataset


If you find AttGAN useful in your research work, please consider citing:

author={Z. {He} and W. {Zuo} and M. {Kan} and S. {Shan} and X. {Chen}},
journal={IEEE Transactions on Image Processing},
title={AttGAN: Facial Attribute Editing by Only Changing What You Want},
keywords={Face;Facial features;Task analysis;Decoding;Image reconstruction;Hair;Gallium nitride;Facial attribute editing;attribute style manipulation;adversarial learning},

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.