This repository provides a PyTorch implementation of StarGAN. StarGAN can flexibly translate an input image to any desired target domain using only a single generator and a discriminator. The demo video for StarGAN can be found here.
StarGAN: Unified Generative Adversarial Networks for Multi-Domain Image-to-Image Translation
Yunjey Choi 1,2, Minje Choi 1,2, Munyoung Kim 2,3, Jung-Woo Ha 2, Sung Kim 2,4, and Jaegul Choo 1,2
1 Korea University, 2 Clova AI Research (NAVER Corp.), 3 The College of New Jersey, 4 HKUST
IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2018 (Oral)
- Python 3.5+
- PyTorch 0.4.0
- TensorFlow 1.3+ (optional for tensorboard)
$ git clone https://github.com/liangxiaoyun/Facial-Attribute-Transfer
To download the CelebA dataset:
$ bash download.sh celeba
To download the RaFD dataset, you must request access to the dataset from the Radboud Faces Database website. Then, you need to create a folder structure as described here.
To train StarGAN on CelebA, run the training script below. See here for a list of selectable attributes in the CelebA dataset. If you change the selected_attrs
argument, you should also change the c_dim
argument accordingly.
$CUDA_VISIBLE_DEVICES=1 python main.py --mode train --dataset CelebA --image_size 128 --c_dim 5 --celeba_image_dir data/CelebA/CelebA_nocrop/images --attr_path data/list_attr_celeba.txt --sample_dir stargan/Celeba/samples --log_dir stargan/Celeba/logs --model_save_dir stargan/Celeba/models --result_dir stargan/Celeba/results --num_iters 300000
To train StarGAN on RaFD:
$CUDA_VISIBLE_DEVICES=1 python main.py --mode train --dataset data/RaFD/train --image_size 128 --c_dim 7 --sample_dir stargan/rafd/samples --log_dir stargan/rafd/logs --model_save_dir stargan/rafd/models --result_dir stargan/rafd/results
To train StarGAN on both CelebA and RafD:
$python main.py --mode=train --dataset Both --image_size 128 --c_dim 5 --c2_dim 7 --sample_dir stargan/both/samples --log_dir stargan/both/logs --model_save_dir stargan/both/models --result_dir stargan/both/results
To train StarGAN on your own dataset, create a folder structure in the same format as RaFD and run the command:
$python main.py --mode train --dataset RaFD --image_size 128 --c_dim 7 --rafd_image_dir data/KDEF/train --sample_dir stargan/KDEF/samples --log_dir stargan/KDEF/logs --model_save_dir stargan/KDEF/models --result_dir stargan/KDEF/results
To test StarGAN on CelebA:
$python main.py --mode test --dataset CelebA --image_size 128 --c_dim 5 --model_save_dir stargan/Celeba/models --result_dir stargan/Celeba/results --celeba_image_dir data/testimage--selected_attrs Black_Hair Blond_Hair Brown_Hair Male Young --celeba_image_dir data/testimage --attr_path data/test_list_attr_celeba.txt ----test_iters 300000
To test StarGAN on RaFD:
$python main.py --mode test --dataset RaFD --image_size 128 --c_dim 7 --model_save_dir stargan/rafd/models --result_dir stargan/rafd/results --rafd_image_dir data/testimage --attr_path data/test_list_attr_celeba.txt
To test StarGAN on both CelebA and RaFD:
$python main.py --mode test --dataset Both --image_size 128 --c_dim 5 --c2_dim 7 --model_save_dir stargan/both/models --result_dir stargan/both/results --rafd_image_dir data/RaFD/test --celeba_image_dir data/testimage --attr_path data/test_list_attr_celeba.txt
To test StarGAN on your own dataset:
$python main.py --mode test --dataset RaFD --image_size 128 --c_dim 7 --model_save_dir stargan/KDEF/models --result_dir stargan/KDEF/results --rafd_image_dir data/testimage --attr_path data/test_list_attr_celeba.txt
To download a pretrained model checkpoint, run the script below. The pretrained model checkpoint will be downloaded and saved into stargan_celeba_256/models
directory.
$ bash download.sh pretrained-celeba-256x256
To translate images using the pretrained model, run the evaluation script below. The translated images will be saved into stargan/stargan_celeba_256/results
directory.
$ python main.py --mode test --dataset CelebA --image_size 256 --c_dim 5 --model_save_dir='stargan/stargan_celeba_256/models' --result_dir='stargan/stargan_celeba_256/results'
$pip install pyinstaller
$pyinstaller main.py
生成build和dist文件夹,双击,dist/main/main.exe即可打开GUI界面,如GUI_image.png