AttentionGAN for Unpaired Image-to-Image Translation & Multi-Domain Image-to-Image Translation

Overview

License CC BY-NC-SA 4.0 Python 3.6 Packagist Last Commit Maintenance Contributing Ask Me Anything !

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.

Framework

Comparsion with State-of-the-Art Methods

Selfie To Anime Translation

Result

Horse to Zebra Translation

Result
Result

Zebra to Horse Translation

Result

Apple to Orange Translation

Result

Orange to Apple Translation

Result

Map to Aerial Photo Translation

Result

Aerial Photo to Map Translation

Result

Style Transfer

Result

Visualization of Learned Attention Masks

Selfie to Anime Translation

Result

Horse to Zebra Translation

Attention

Zebra to Horse Translation

Attention

Apple to Orange Translation

Attention

Orange to Apple Translation

Attention

Map to Aerial Photo Translation

Attention

Aerial Photo to Map Translation

Attention

Extended Paper | Conference Paper

AttentionGAN: Unpaired Image-to-Image Translation using Attention-Guided Generative Adversarial Networks.
Hao Tang1, Hong Liu2, Dan Xu3, Philip H.S. Torr3 and Nicu Sebe1.
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 | Code

Are you looking for AttentionGAN-v1 for Multi-Domain Image-to-Image Translation?

Paper | Code

Facial Expression-to-Expression Translation

Result Order: The Learned Attention Masks, The Learned Content Masks, Final Results

Facial Attribute Transfer

Attention Order: The Learned Attention Masks, The Learned Content Masks, Final Results

Result Order: The Learned Attention Masks, AttentionGAN, StarGAN

License

Creative Commons License
Copyright (C) 2019 University of Trento, Italy.

All rights reserved. Licensed under the CC BY-NC-SA 4.0 (Attribution-NonCommercial-ShareAlike 4.0 International)

The code is released for academic research use only. For commercial use, please contact [email protected].

Installation

Clone this repo.

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

pip install -r requirements.txt (for pip users)

or

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

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.
  • 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: Official Implementation
  • KID or Here: Suggested by UGATIT. 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, GestureGAN, and 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 ([email protected]).

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 [email protected]. Some of our projects are listed here.


Figure out what you like. Try to become the best in the world of it.

Comments
  • Model loss discriminator loss drops to 0

    Model loss discriminator loss drops to 0

    Firstly can I just say this that your paper is well written and really simple to understand. Taking references from your code I recreated the implementation in a jupyter notebook but I have come to notice that no matter what dataset I try (tried monet2photo, iPhone2dslr , selfie2anime and horse2zebra) after a few epochs when it seems like the model is starting to generate desired results the discriminator loss drops to 0 all of a sudden and the image produced is from the same domain rather than the previously outputted. I was using the default settings for every dataset (if needed I’ll upload the notebook too) Thanks!

    opened by stqc 8
  • experimental on RaFD dataset like Fig. 8

    experimental on RaFD dataset like Fig. 8

    Hi, thank you for your sharing . you paper so clear and have many detail about experimental ,this is very important !! I want to reimplement Fig 8 preformance but in your code , I do not find any conditional D or G.

    Would you supply about Fig 8 code ? or some detailed architcuture? Thank your

    opened by Johnson-yue 7
  • Permission to post a simplified version?

    Permission to post a simplified version?

    I hope you are doing well, since our last conversation I have been tinkering around with your work a little experimenting with different datasets.... I have also made a simplified version of your work in jupyter notebook and I wanted to know if I am allowed to post it over at my github? and if so would you like any specific additions to the notebook other than the citation?

    Thanks and regards!

    opened by stqc 5
  • How many epochs do you set up in your article?

    How many epochs do you set up in your article?

    Thank you for sharing! You have proposed an inspiring method on unpaired image translation. there is a little question, how many epochs do you set up in your article? Cause I download your pre-trained horse2zebra model which has trained 60 epochs, but the results are not so well as your articles'.

    BTW, maybe there is a spelling mistake in your markdown home page, this is, 'Ecaluation Code' maybe indicate 'evaluation code'.

    Thx again.

    opened by peachis 5
  • About the code

    About the code

    Hi! The dicriminator of AttentionGAN in your implementation is not the case in your paper. There is no "mask_A" or "mask_B" as input to discriminator. It is different from your paper where claimed "where DY A aims to distinguish between the generated image pairs [My;GX!Y (x)] and the real image pairs [My; y]." Can you explain this?

    opened by DLwbm123 3
  • Training from A to B Resulting in B to A effects

    Training from A to B Resulting in B to A effects

    When I check the webpage in checkpoints directory, the fake_B is almost the same as real_A, while fake_A has an effect of changing to real_B style.

    I'm using my own dataset. Is there any special requirement for the datasets, for example, only translating from simpler images to images with more patterns and details is okay?

    opened by DIMPLY 2
  • Checkpoints Missing After Successful Training

    Checkpoints Missing After Successful Training

    I used the repo to work on horse2zebra dataset as a test. However, after finishing 60 epochs, although the logs (see below) said multiple .pt files were saved to ./chackpoints, nothing is actually shown there.

    saving the model at the end of epoch 60, iters 80160
    End of epoch 60 / 60 	 Time Taken: 444 sec
    

    I used exactly the same command line in scripts/train_attentiongan.sh -- basically copied it to Colab.

    I briefly checked the code and believe the checkpoints should have been saved to the default path, because I didn't specify the flags, just like in scripts/train_attentiongan.sh.

    Did anyone encountered the same problem?

    opened by DIMPLY 2
  • Confusion about Attention Mask、Foreground Attention Mask、Background Attention Mask

    Confusion about Attention Mask、Foreground Attention Mask、Background Attention Mask

    Hi,HaoTang:

    Thanks for you great work! I have a puzzle about your paper.

    In “AttentionGAN:Unpaired Image-to-Image Translation using Attention-Guided Generative Adversarial Networks”, the attention mask mentioned in fig.23 corresponds to the foreground attention mask or background attention mask in Fig.3?

    opened by ischansgithub 2
  • Does the attention-guided discriminator take the attention masks as input?

    Does the attention-guided discriminator take the attention masks as input?

    Does the attention-guided discriminator take the attention masks as input as the paper mentioned (neither NLayerDiscriminator or PixelDiscriminator do)? If so, where is the corresponding code? Thanks!

    opened by JuiChang 2
  • Attention-Guided Adversarial Loss.

    Attention-Guided Adversarial Loss.

    you mention that We propose the attention-guided adversarial loss for training the attentionguide discriminators.But in the code seems that you didn't apply that.

    opened by xuxiaochun025 2
  • pretrained model

    pretrained model

    Thanks for your great work! But I can not download your pretrained model, could you please upload it to baidu cloud or Google cloud? Or email it to me ? [email protected] Thanks a lot!!

    opened by pytyeah 1
  • cant download pretrained model under AttentionGAN-v1-multi/stargan_rafd

    cant download pretrained model under AttentionGAN-v1-multi/stargan_rafd

    i am having trouble downloading the pretrained model, that is trained on the rafd dataset. It creates the checkpoint folder, but does not download the model. I tried to follow the link that was described in the file but access is forbidden. Is there a way for me to get access or download this file? thank you in advance.

    opened by KayolanSenp 0
  • Does SchemeⅡ performance better than SchemeⅠ in facial expression transfer?

    Does SchemeⅡ performance better than SchemeⅠ in facial expression transfer?

    Does SchemeⅡ performance better than SchemeⅠ in facial expression transfer? I see that you have shown the effect comparison between Scheme 1 and Scheme 2 in your paper, In the figure, it seems that SchemeⅡ will perform better in facial expression transfer. But in the paper, there is no quantitative analysis of facial expression between the two schemes. Have you ever made some comparison? I want to know more about whether SchemeⅡ can edit facial expressions better than Scheme Ⅰ. Thanks a lot! @Ha0Tang image

    opened by laoliu97 0
  • Attention_mask(calls My in paper) is not used as input of discriminator

    Attention_mask(calls My in paper) is not used as input of discriminator

    Hello, I'm very interested in your work. After reading the v1 paper and code, I found that there is no attention_mask(My) and composite_images (calls Gy in paper)are put into D together, but only the composite_images Gy(Gy=RyMy+x(1-My)) were put into D. Have you deleted this part of the code? The following figure is the relevant formula in the paper, but it is not shows in the code. image

    opened by laoliu97 1
  • Question: Code structure

    Question: Code structure

    Hi! I have a question about the code structure.

    I really like the structure of this code base, i.e. the way options are handled, the directory / module structure etc. I have seen this structure across multiple projects in different pytorch experiments now and simply wanted to learn if there is some sort of "template" or example code base you were using.

    opened by gogobd 0
  • About Reg Loss in AttentionGAN-v1

    About Reg Loss in AttentionGAN-v1

    I just use AttentionGAN-V1 combined with my GAN model, and my reg loss decrease to about 0,165 and then stay still,

    looking the attention_mask variable I found that after iterations and epochs, all voxels stay about 0.26 with not any attention i need (can't detect any domain gap?? after training) and then stop update each voxel's probability (from 0 to 1),

    but the result did better for non-attention situation, could you guide me how to fix this or its really normal to this situation?

    In my opinion I think, though GAN maybe stable after epochs but attention from generator may still catch the difference between domains, and highlight the main different part.

    @Ha0Tang , please and Thanks alot, best wishes.

    opened by DISAPPEARED13 0
Owner
Hao Tang
To develop a complete mind: Study the science of art; Study the art of science. Learn how to see. Realize that everything connects to everything else.
Hao Tang
Unpaired Caricature Generation with Multiple Exaggerations

CariMe-pytorch The official pytorch implementation of the paper "CariMe: Unpaired Caricature Generation with Multiple Exaggerations" CariMe: Unpaired

Gu Zheng 37 Dec 30, 2022
Variational Attention: Propagating Domain-Specific Knowledge for Multi-Domain Learning in Crowd Counting (ICCV, 2021)

DKPNet ICCV 2021 Variational Attention: Propagating Domain-Specific Knowledge for Multi-Domain Learning in Crowd Counting Baseline of DKPNet is availa

null 19 Oct 14, 2022
Code of U2Fusion: a unified unsupervised image fusion network for multiple image fusion tasks, including multi-modal, multi-exposure and multi-focus image fusion.

U2Fusion Code of U2Fusion: a unified unsupervised image fusion network for multiple image fusion tasks, including multi-modal (VIS-IR, medical), multi

Han Xu 129 Dec 11, 2022
Code for CVPR2021 "Visualizing Adapted Knowledge in Domain Transfer". Visualization for domain adaptation. #explainable-ai

Visualizing Adapted Knowledge in Domain Transfer @inproceedings{hou2021visualizing, title={Visualizing Adapted Knowledge in Domain Transfer}, auth

Yunzhong Hou 80 Dec 25, 2022
[CVPR2021] Domain Consensus Clustering for Universal Domain Adaptation

[CVPR2021] Domain Consensus Clustering for Universal Domain Adaptation [Paper] Prerequisites To install requirements: pip install -r requirements.txt

Guangrui Li 84 Dec 26, 2022
Official pytorch implementation of "Feature Stylization and Domain-aware Contrastive Loss for Domain Generalization" ACMMM 2021 (Oral)

Feature Stylization and Domain-aware Contrastive Loss for Domain Generalization This is an official implementation of "Feature Stylization and Domain-

null 22 Sep 22, 2022
CDTrans: Cross-domain Transformer for Unsupervised Domain Adaptation

CDTrans: Cross-domain Transformer for Unsupervised Domain Adaptation [arxiv] This is the official repository for CDTrans: Cross-domain Transformer for

null 238 Dec 22, 2022
CDTrans: Cross-domain Transformer for Unsupervised Domain Adaptation

[ICCV2021] TransReID: Transformer-based Object Re-Identification [pdf] The official repository for TransReID: Transformer-based Object Re-Identificati

DamoCV 569 Dec 30, 2022
Implementation for "Domain-Specific Bias Filtering for Single Labeled Domain Generalization"

DSBF Introduction This repository contains the implementation code for paper: Domain-Specific Bias Filtering for Single Labeled Domain Generalization

ScottYuan 7 Jan 5, 2023
A Pytorch Implementation of [Source data‐free domain adaptation of object detector through domain

A Pytorch Implementation of Source data‐free domain adaptation of object detector through domain‐specific perturbation Please follow Faster R-CNN and

null 1 Dec 25, 2021
Code to reproduce the experiments in the paper "Transformer Based Multi-Source Domain Adaptation" (EMNLP 2020)

Transformer Based Multi-Source Domain Adaptation Dustin Wright and Isabelle Augenstein To appear in EMNLP 2020. Read the preprint: https://arxiv.org/a

CopeNLU 36 Dec 5, 2022
PyTorch code for the paper "Curriculum Graph Co-Teaching for Multi-target Domain Adaptation" (CVPR2021)

PyTorch code for the paper "Curriculum Graph Co-Teaching for Multi-target Domain Adaptation" (CVPR2021) This repo presents PyTorch implementation of M

Evgeny 79 Dec 19, 2022
PyTorch implementation of CDistNet: Perceiving Multi-Domain Character Distance for Robust Text Recognition

PyTorch implementation of CDistNet: Perceiving Multi-Domain Character Distance for Robust Text Recognition The unofficial code of CDistNet. Now, we ha

null 25 Jul 20, 2022
Implementation of "Unsupervised Domain Adaptive 3D Detection with Multi-Level Consistency"

Unsupervised Domain Adaptive 3D Detection with Multi-Level Consistency (ICCV2021) Paper Link: https://arxiv.org/abs/2107.11355 This implementation bui

null 32 Nov 17, 2022
STEM: An approach to Multi-source Domain Adaptation with Guarantees

STEM: An approach to Multi-source Domain Adaptation with Guarantees Introduction This is the official implementation of ``STEM: An approach to Multi-s

null 5 Dec 19, 2022
Code for Emergent Translation in Multi-Agent Communication

Emergent Translation in Multi-Agent Communication PyTorch implementation of the models described in the paper Emergent Translation in Multi-Agent Comm

Facebook Research 75 Jul 15, 2022
A multi-entity Transformer for multi-agent spatiotemporal modeling.

baller2vec This is the repository for the paper: Michael A. Alcorn and Anh Nguyen. baller2vec: A Multi-Entity Transformer For Multi-Agent Spatiotempor

Michael A. Alcorn 56 Nov 15, 2022
Multi-Scale Geometric Consistency Guided Multi-View Stereo

ACMM [News] The code for ACMH is released!!! [News] The code for ACMP is released!!! About ACMM is a multi-scale geometric consistency guided multi-vi

Qingshan Xu 118 Jan 4, 2023
AMTML-KD: Adaptive Multi-teacher Multi-level Knowledge Distillation

AMTML-KD: Adaptive Multi-teacher Multi-level Knowledge Distillation

Frank Liu 26 Oct 13, 2022