https://github.com/Ha0Tang/AttentionGAN
AttentionGAN for Unpaired Image-to-Image Translation & Multi-Domain Image-to-Image Translation
https://github.com/Ha0Tang/AttentionGAN
adversarial-networks attention-model computer-vision cyclegan deep-learning gans geometry ijcnn image-generation image-to-image-translation image-translation multi-domain pytorch unpaired
Last synced: 5 months ago
JSON representation
AttentionGAN for Unpaired Image-to-Image Translation & Multi-Domain Image-to-Image Translation
- Host: GitHub
- URL: https://github.com/Ha0Tang/AttentionGAN
- Owner: Ha0Tang
- License: other
- Created: 2019-07-09T13:54:20.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-06T21:30:54.000Z (about 2 years ago)
- Last Synced: 2024-08-04T03:11:10.381Z (about 1 year ago)
- Topics: adversarial-networks, attention-model, computer-vision, cyclegan, deep-learning, gans, geometry, ijcnn, image-generation, image-to-image-translation, image-translation, multi-domain, pytorch, unpaired
- Language: Python
- Homepage:
- Size: 207 MB
- Stars: 628
- Watchers: 12
- Forks: 94
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://github.com/Ha0Tang/AttentionGAN/blob/master/LICENSE.md)



[]((https://github.com/Ha0Tang/AttentionGAN/graphs/commit-activity))

# AttentionGAN-v2 for Unpaired Image-to-Image Translation
## AttentionGAN-v2 Framework
The proposed generator learns both foreground and background attentions. It uses the foreground attention to select from the generated output for the foreground regions, while uses the background attention to maintain the background information from the input image. Please refer to our papers for more details.
## Comparsion with State-of-the-Art Methods
### Selfie To Anime Translation
### Horse to Zebra Translation

### Zebra to Horse Translation
### Apple to Orange Translation
### Orange to Apple Translation
### Map to Aerial Photo Translation
### Aerial Photo to Map Translation
### Style Transfer
## Visualization of Learned Attention Masks
### Selfie to Anime Translation
### Horse to Zebra Translation
### Zebra to Horse Translation
### Apple to Orange Translation
### Orange to Apple Translation
### Map to Aerial Photo Translation
### Aerial Photo to Map Translation
### [Extended Paper](https://arxiv.org/abs/1911.11897) | [Conference Paper](https://arxiv.org/abs/1903.12296)
AttentionGAN: Unpaired Image-to-Image Translation using Attention-Guided Generative Adversarial Networks.
[Hao Tang](http://disi.unitn.it/~hao.tang/)1, [Hong Liu](https://scholar.google.com/citations?user=4CQKG8oAAAAJ&hl=en)2, [Dan Xu](http://www.robots.ox.ac.uk/~danxu/)3, [Philip H.S. Torr](https://scholar.google.com/citations?user=kPxa2w0AAAAJ&hl=en)3 and [Nicu Sebe](http://disi.unitn.it/~sebe/)1.
1University of Trento, Italy, 2Peking University, China, 3University of Oxford, UK.
In TNNLS 2021 & IJCNN 2019 Oral.
The repository offers the official implementation of our paper in PyTorch.#### Are you looking for AttentionGAN-v1 for Unpaired Image-to-Image Translation?
> [Paper](https://arxiv.org/abs/1903.12296) | [Code](./AttentionGAN-v1)#### Are you looking for AttentionGAN-v1 for Multi-Domain Image-to-Image Translation?
> [Paper](https://arxiv.org/abs/1903.12296) | [Code](./AttentionGAN-v1-multi)##### Facial Expression-to-Expression Translation

Order: The Learned Attention Masks, The Learned Content Masks, Final Results##### Facial Attribute Transfer

Order: The Learned Attention Masks, The Learned Content Masks, Final Results
Order: The Learned Attention Masks, AttentionGAN, StarGAN### [License](./LICENSE.md)
Copyright (C) 2019 University of Trento, Italy.All rights reserved.
Licensed under the [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode) (**Attribution-NonCommercial-ShareAlike 4.0 International**)The code is released for academic research use only. For commercial use, please contact [bjdxtanghao@gmail.com](bjdxtanghao@gmail.com).
## Installation
Clone this repo.
```bash
git clone https://github.com/Ha0Tang/AttentionGAN
cd AttentionGAN/
```This code requires PyTorch 0.4.1+ and python 3.6.9+. Please install dependencies by
```bash
pip install -r requirements.txt (for pip users)
```
or```bash
./scripts/conda_deps.sh (for Conda users)
```To reproduce the results reported in the paper, you would need an NVIDIA Tesla V100 with 16G memory.
## Dataset Preparation
Download the datasets using the following script. Please cite their paper if you use the data. Try twice if it fails the first time!
```
sh ./datasets/download_cyclegan_dataset.sh dataset_name
```
The selfie2anime dataset can be download [here](https://drive.google.com/file/d/1xOWj1UVgp6NKMT3HbPhBbtq2A4EDkghF/view).## AttentionGAN Training/Testing
- Download a dataset using the previous script (e.g., horse2zebra).
- To view training results and loss plots, run `python -m visdom.server` and click the URL [http://localhost:8097](http://localhost:8097).
- Train a model:
```
sh ./scripts/train_attentiongan.sh
```
- To see more intermediate results, check out `./checkpoints/horse2zebra_attentiongan/web/index.html`.
- How to continue train? Append `--continue_train --epoch_count xxx` on the command line.
- Test the model:
```
sh ./scripts/test_attentiongan.sh
```
- The test results will be saved to a html file here: `./results/horse2zebra_attentiongan/latest_test/index.html`.## Generating Images Using Pretrained Model
- You need download a pretrained model (e.g., horse2zebra) with the following script:
```
sh ./scripts/download_attentiongan_model.sh horse2zebra
```
- The pretrained model is saved at `./checkpoints/{name}_pretrained/latest_net_G.pth`.
- Then generate the result using
```
python test.py --dataroot ./datasets/horse2zebra --name horse2zebra_pretrained --model attention_gan --dataset_mode unaligned --norm instance --phase test --no_dropout --load_size 256 --crop_size 256 --batch_size 1 --gpu_ids 0 --num_test 5000 --epoch latest --saveDisk
```
The results will be saved at `./results/`. Use `--results_dir {directory_path_to_save_result}` to specify the results directory. Note that if you want to save the intermediate results and have enough disk space, remove `--saveDisk` on the command line.- For your own experiments, you might want to specify --netG, --norm, --no_dropout to match the generator architecture of the trained model.
### Image Translation with Geometric Changes Between Source and Target Domains
For instance, if you want to run experiments of Selfie to Anime Translation. Usage: replace `attention_gan_model.py` and `networks` with the ones in the `AttentionGAN-geo` folder.### Test the Pretrained Model
Download data and pretrained model according above instructions.`python test.py --dataroot ./datasets/selfie2anime/ --name selfie2anime_pretrained --model attention_gan --dataset_mode unaligned --norm instance --phase test --no_dropout --load_size 256 --crop_size 256 --batch_size 1 --gpu_ids 0 --num_test 5000 --epoch latest`
### Train a New Model
`python train.py --dataroot ./datasets/selfie2anime/ --name selfie2anime_attentiongan --model attention_gan --dataset_mode unaligned --pool_size 50 --no_dropout --norm instance --lambda_A 10 --lambda_B 10 --lambda_identity 0.5 --load_size 286 --crop_size 256 --batch_size 4 --niter 100 --niter_decay 100 --gpu_ids 0 --display_id 0 --display_freq 100 --print_freq 100`### Test the Trained Model
`python test.py --dataroot ./datasets/selfie2anime/ --name selfie2anime_attentiongan --model attention_gan --dataset_mode unaligned --norm instance --phase test --no_dropout --load_size 256 --crop_size 256 --batch_size 1 --gpu_ids 0 --num_test 5000 --epoch latest`## Evaluation Code
- [FID](https://github.com/bioinf-jku/TTUR): Official Implementation
- [KID](https://github.com/taki0112/GAN_Metrics-Tensorflow) or [Here](https://github.com/Ha0Tang/AttentionGAN/tree/master/scripts/GAN_Metrics-Tensorflow): Suggested by [UGATIT](https://github.com/taki0112/UGATIT/issues/64).
Install Steps: `conda create -n python36 pyhton=3.6 anaconda` and `pip install --ignore-installed --upgrade tensorflow==1.13.1`. If you encounter the issue `AttributeError: module 'scipy.misc' has no attribute 'imread'`, please do `pip install scipy==1.1.0`.## Citation
If you use this code for your research, please cite our papers.
```
@article{tang2021attentiongan,
title={AttentionGAN: Unpaired Image-to-Image Translation using Attention-Guided Generative Adversarial Networks},
author={Tang, Hao and Liu, Hong and Xu, Dan and Torr, Philip HS and Sebe, Nicu},
journal={IEEE Transactions on Neural Networks and Learning Systems (TNNLS)},
year={2021}
}@inproceedings{tang2019attention,
title={Attention-Guided Generative Adversarial Networks for Unsupervised Image-to-Image Translation},
author={Tang, Hao and Xu, Dan and Sebe, Nicu and Yan, Yan},
booktitle={International Joint Conference on Neural Networks (IJCNN)},
year={2019}
}
```## Acknowledgments
This source code is inspired by [CycleGAN](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix), [GestureGAN](https://github.com/Ha0Tang/GestureGAN), and [SelectionGAN](https://github.com/Ha0Tang/SelectionGAN).## Contributions
If you have any questions/comments/bug reports, feel free to open a github issue or pull a request or e-mail to the author Hao Tang ([bjdxtanghao@gmail.com](bjdxtanghao@gmail.com)).## Collaborations
I'm always interested in meeting new people and hearing about potential collaborations. If you'd like to work together or get in contact with me, please email bjdxtanghao@gmail.com. Some of our projects are listed [here](https://github.com/Ha0Tang).
___
*Figure out what you like. Try to become the best in the world of it.*