{"id":19768582,"url":"https://github.com/prinsphield/elegant","last_synced_at":"2025-04-13T10:58:20.458Z","repository":{"id":41553761,"uuid":"127078140","full_name":"Prinsphield/ELEGANT","owner":"Prinsphield","description":"ELEGANT: Exchanging Latent Encodings with GAN for Transferring Multiple Face Attributes","archived":false,"fork":false,"pushed_at":"2019-09-10T20:19:13.000Z","size":2019,"stargazers_count":261,"open_issues_count":7,"forks_count":42,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-27T02:11:55.712Z","etag":null,"topics":["face-attribute-transfer","generative-adversarial-network","image-interpolation","multi-attribute"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/1803.10562","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Prinsphield.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-28T03:24:53.000Z","updated_at":"2025-03-01T21:31:27.000Z","dependencies_parsed_at":"2022-09-21T12:50:21.848Z","dependency_job_id":null,"html_url":"https://github.com/Prinsphield/ELEGANT","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prinsphield%2FELEGANT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prinsphield%2FELEGANT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prinsphield%2FELEGANT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prinsphield%2FELEGANT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Prinsphield","download_url":"https://codeload.github.com/Prinsphield/ELEGANT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248703196,"owners_count":21148117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["face-attribute-transfer","generative-adversarial-network","image-interpolation","multi-attribute"],"created_at":"2024-11-12T04:39:14.765Z","updated_at":"2025-04-13T10:58:20.436Z","avatar_url":"https://github.com/Prinsphield.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ELEGANT: Exchanging Latent Encodings with GAN for Transferring Multiple Face Attributes\n\nTaihong Xiao, Jiapeng Hong and Jinwen Ma\n\nPlease cite our paper if you find it useful to your research.\n```\n@InProceedings{Xiao_2018_ECCV,\n    author = {Xiao, Taihong and Hong, Jiapeng and Ma, Jinwen},\n    title = {ELEGANT: Exchanging Latent Encodings with GAN for Transferring Multiple Face Attributes},\n    booktitle = {Proceedings of the European Conference on Computer Vision (ECCV)},\n    pages = {172--187},\n    month = {September},\n    year = {2018}\n}\n```\n\n## Introduction\n\nThis repo is the pytorch implementation of our [paper](https://arxiv.org/abs/1803.10562).\nELEGANT is a novel model for transferring multiple face attributes by exchanging latent encodings.\nThe model framework is shown below.\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg align=\"center\" src=\"extra/model.jpg\" width=\"900\" alt=\"model\"\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\nThe ELEGANT Model Framework\n\u003c/div\u003e\n\u003cbr/\u003e\n\n**If you want to train or test the model on your own images, please do the facial landmark alignment first. We preprocess the whole datasete using 5p alignment [here](https://github.com/Prinsphield/ELEGANT/blob/master/preprocess.py). However, you can use other alignment algorithm as long as it is consistent in both training and testing phases.**\n\n\n## Requirements\n\n- [Python 2.7 or 3.x](https://www.python.org/)\n- [OpenCV 3](https://opencv.org/)\n- [Pytorch 0.3](http://pytorch.org/)\n- [TensorboardX](https://github.com/lanpa/tensorboard-pytorch)\n\n## Training on CelebA dataset\n\n0. Download [celebA](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html) dataset and unzip it into\n`datasets` directory. There are various source providers for CelebA datasets. To ensure that the\nsize of downloaded images is correct, please run `identify datasets/celebA/data/000001.jpg`. The\nsize should be 409 x 687 if you are using the same dataset. Besides, please ensure that you have\nthe following directory tree structure in your repo.\n\n```\n├── datasets\n│   └── celebA\n│       ├── data\n│       ├── images.list\n│       ├── list_attr_celeba.txt\n│       └── list_landmarks_celeba.txt\n```\n\n1. Run `python preprocess.py`. It will take only few minutes to preprocess all images.\nA new directory `datasets/celebA/align_5p` will be created.\n\n2. Run `python ELEGANT.py -m train -a Bangs Mustache -g 0` to train ELEGANT with respect to two attributes\n`Bangs` and `Mustache` simultaneuously. You can play with other attributes as well. Please refer\nto `list_attr_celeba.txt` for all available attributes. If training ELEGANT with more than one gpu cards,\nyou can accordingly increase the batch size, which is indicated in the first number of `nchw` in `dataset.py`.\n\n3. Run `tensorboard --logdir=./train_log/log --port=6006` to watch your training process.\nYou can use tags matching for inspecting one group of images.\nFor example, if you type `0_04` in the image tags matching box, then a group of 10 images should be displayed\ntogether, including two original images, four residual images and four generated images.\nIn the notation `0_04`, `0` indicates the first attribute and the `04` indicates the 4-th group.\n\n\n## Testing\n\nWe provide four types of mode for testing. Let me explain all the parameters for testing.\n\n- `-a`: All attributes' names.\n- `-r`: Restore checkpoint.\n- `-g`: The GPU id(s) for testing.\n\t- Don't add this parameter to your shell command if you don't want to use gpu for testing.\n    - No more than 1 GPU should be specified during test, because 1 image cannot be split into multiple GPUs.\n- `--swap`: Swap attribute of two images.\n- `--linear`: Linear interpolation by adding or removing one certain attribute.\n- `--matrix`: Matrix interpolation with respect to one or two attributes.\n- `--swap_list`: The attribute id(s) for testing.\n\t- For example, `--swap_list 0` indicates the first attribute.\n\t- Receives **two** integers only in the interpolation with respect to two attributes.\n\t- In other cases, **only one** integer is required.\n- `--input`: Input images path that you want to transfer.\n- `--target`: Target image(s) path for reference.\n\t- **Only one** target image is needed in the `--swap` and `--linear` mode.\n\t- **Three** target images are needed in the `--matrix` mode with respect to one attribute.\n\t- **Two** target images are required in the `--matrix` mode with respect to two attributes.\n- `-s`: The output size for interpolation.\n\t- **One** integer is needed in the `--linear` mode.\n\t- **Two** integers are required for the `--matrix` mode.\n\n### 1. Swap Attribute\n\nWe can swap the `Mustache` attribute of two images. Here `--swap_list 1` indicates the second\nattribute should be swapped and `-r 34000` means restoring trained model of step 34000.\nYou can choose the best model by inspecting the quality of generated images in tensorboard or\nin the directory `train_log/img/`.\n\n    python ELEGANT.py -m test -a Bangs Mustache -r 34000 --swap --swap_list 1 --input ./images/goodfellow_aligned.png --target ./images/bengio_aligned.png\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg align=\"center\" src=\"extra/swap.jpg\" width=\"600\" alt=\"swap\"\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\nSwap Mustache\n\u003c/div\u003e\n\u003cbr/\u003e\n\n\n### 2. Linear Interpolation\n\nWe can see the linear interpolation results of adding mustache to Bengio by running the following.\n`-s 4` indicates the number of intermediate images.\n\n    python ELEGANT.py -m test -a Bangs Mustache -r 34000 --linear --swap_list 1 --input ./images/bengio_aligned.png --target ./images/goodfellow_aligned.png -s 4\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg align=\"center\" src=\"extra/linear_interpolation.jpg\" width=\"900\" alt=\"linear\"\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\nLinear Interpolation on Mustache\n\u003c/div\u003e\n\u003cbr/\u003e\n\n\n### 3. Matrix Interpolation with Respect to One Attribute\n\nWe can also add different kinds of bangs to a single person. Here, `--swap_list 0` indicates we are\ndealing with the first attribute, and there are three target images provided for reference.\n\n    python ELEGANT.py -m test -a Bangs Mustache -r 34000 --matrix --swap_list 0 --input ./images/ng_aligned.png --target ./images/bengio_aligned.png ./images/goodfellow_aligned.png ./images/jian_sun_aligned.png -s 4 4\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg align=\"center\" src=\"extra/matrix_interpolation1.jpg\" width=\"900\" alt=\"matrix1\"\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\nMatrix Interpolation on different Bangs\n\u003c/div\u003e\n\u003cbr/\u003e\n\n\n### 4. Matrix Interpolation with Respect to Two Attributes\n\nWe can transfer two attributes simultaneously by running the following command.\n\n    python ELEGANT.py -m test -a Bangs Mustache -r 34000 --matrix --swap_list 0 1 --input ./images/lecun_aligned.png --target ./images/bengio_aligned.png ./images/goodfellow_aligned.png -s 4 4\n\nThe original image gradually owns the first attribute Bangs in the vertical direction and the second\nattribute Mustache in the horizontal direction.\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg align=\"center\" src=\"extra/matrix_interpolation2.jpg\" width=\"900\" alt=\"matrix2\"\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\nMatrix Interpolation on Bangs and Mustache\n\u003c/div\u003e\n\u003cbr/\u003e\n\n## References\n\n- [GeneGAN: Learning Object Transfiguration and Attribute Subspace from Unpaired Data](https://github.com/Prinsphield/GeneGAN)\n- [DNA-GAN: Learning Disentangled Representations from Multi-Attribute Images](https://github.com/Prinsphield/DNA-GAN)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinsphield%2Felegant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprinsphield%2Felegant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinsphield%2Felegant/lists"}