Official PyTorch implementation of U-GAT-IT: Unsupervised Generative Attentional Networks with Adaptive Layer-Instance Normalization for Image-to-Image Translation

Overview

U-GAT-IT — Official PyTorch Implementation

: Unsupervised Generative Attentional Networks with Adaptive Layer-Instance Normalization for Image-to-Image Translation

Paper | Official Tensorflow code

The results of the paper came from the Tensorflow code

U-GAT-IT: Unsupervised Generative Attentional Networks with Adaptive Layer-Instance Normalization for Image-to-Image Translation

Abstract We propose a novel method for unsupervised image-to-image translation, which incorporates a new attention module and a new learnable normalization function in an end-to-end manner. The attention module guides our model to focus on more important regions distinguishing between source and target domains based on the attention map obtained by the auxiliary classifier. Unlike previous attention-based methods which cannot handle the geometric changes between domains, our model can translate both images requiring holistic changes and images requiring large shape changes. Moreover, our new AdaLIN (Adaptive Layer-Instance Normalization) function helps our attention-guided model to flexibly control the amount of change in shape and texture by learned parameters depending on datasets. Experimental results show the superiority of the proposed method compared to the existing state-of-the-art models with a fixed network architecture and hyper-parameters.

Usage

├── dataset
   └── YOUR_DATASET_NAME
       ├── trainA
           ├── xxx.jpg (name, format doesn't matter)
           ├── yyy.png
           └── ...
       ├── trainB
           ├── zzz.jpg
           ├── www.png
           └── ...
       ├── testA
           ├── aaa.jpg 
           ├── bbb.png
           └── ...
       └── testB
           ├── ccc.jpg 
           ├── ddd.png
           └── ...

Train

> python main.py --dataset selfie2anime
  • If the memory of gpu is not sufficient, set --light to True

Test

> python main.py --dataset selfie2anime --phase test

Architecture


Results

Ablation study

User study

Comparison

Comments
  • Test Error

    Test Error

    Hi, thanks for this incredible net. I've already trained the dataset, but when I aim to test it and I input the following command: python main.py --phrase test --light true However, I got the error in the log:

    ##### Information #####
    # light :  True
    # dataset :  selfie2anime
    # batch_size :  1
    # iteration per epoch :  1000000
    
    ##### Generator #####
    # residual blocks :  4
    
    ##### Discriminator #####
    # discriminator layer :  6
    
    ##### Weight #####
    # adv_weight :  1
    # cycle_weight :  10
    # identity_weight :  10
    # cam_weight :  1000
     [*] Load FAILURE
     [*] Test finished!
    
    opened by zjxi 6
  • RuntimeError: Found 0 files in subfolders of: dataset\selfie2anime\trainA ?

    RuntimeError: Found 0 files in subfolders of: dataset\selfie2anime\trainA ?

    Hi, when I execute python main.py --dataset selfie2anime ,it tips RuntimeError:

    number of epochs must be larger than or equal to one
    
    ##### Information #####
    # light :  False
    # dataset :  selfie2anime
    # batch_size :  1
    # iteration per epoch :  1000000
    
    ##### Generator #####
    # residual blocks :  4
    
    ##### Discriminator #####
    # discriminator layer :  6
    
    ##### Weight #####
    # adv_weight :  1
    # cycle_weight :  10
    # identity_weight :  10
    # cam_weight :  1000
    Traceback (most recent call last):
      File "main.py", line 83, in <module>
        main()
      File "main.py", line 72, in main
        gan.build_model()
      File "H:\workspace\UGATIT-pytorch\UGATIT.py", line 100, in build_model
        self.trainA = ImageFolder(os.path.join('dataset', self.dataset, 'trainA'), train_transform)
      File "H:\workspace\UGATIT-pytorch\dataset.py", line 107, in __init__
        target_transform=target_transform)
      File "H:\workspace\UGATIT-pytorch\dataset.py", line 47, in __init__
        "Supported extensions are: " + ",".join(extensions)))
    RuntimeError: Found 0 files in subfolders of: dataset\selfie2anime\trainA
    Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif
    

    but this folder hava default female_2321.jpg file image

    opened by danerlt 4
  • I think the train process have some trouble!!!

    I think the train process have some trouble!!!

    Hi, thank you for sharing your code with pytorch, and I find some importance trouble in your code. Maybe cause failed to reimplements model performance!!

    In UGATIT.py -- train function:

    1. when you update D , you do not use

    self.genA2B.eval(), self.genB2A.eval() and in your code here

    fake_B2A.detach(), fake_B2A.detach() ..... but only fake_B2A, fake_B2A. and so on...

    so, when you want to only update D, but meanwhile, the G is also updated. It is the same error in update G

    you can reference SPADE code , if I am wrong ,please tell me

    opened by Johnson-yue 3
  • Why does the UGATIT use 4 discriminators when training?

    Why does the UGATIT use 4 discriminators when training?

        self.genA2B = ResnetGenerator(input_nc=3, output_nc=3, ngf=self.ch, n_blocks=self.n_res, img_size=self.img_size, light=self.light).to(self.device)
        self.genB2A = ResnetGenerator(input_nc=3, output_nc=3, ngf=self.ch, n_blocks=self.n_res, img_size=self.img_size, light=self.light).to(self.device)
        self.disGA = Discriminator(input_nc=3, ndf=self.ch, n_layers=7).to(self.device)
        self.disGB = Discriminator(input_nc=3, ndf=self.ch, n_layers=7).to(self.device)
        self.disLA = Discriminator(input_nc=3, ndf=self.ch, n_layers=5).to(self.device)
        self.disLB = Discriminator(input_nc=3, ndf=self.ch, n_layers=5).to(self.device)
    
    opened by zhanggd001 2
  • Can anyone tell me how to run it?

    Can anyone tell me how to run it?

    I've never write python code.So how can I run it? I try to run python main.py --dataset selfie2anime in cmd.But some errors be displayed: Traceback (most recent call last): File "main.py", line 1, in <module> from UGATIT import UGATIT File "/Users/yh/Personal/UGATIT-pytorch/UGATIT.py", line 2, in <module> from dataset import ImageFolder File "/Users/yh/Personal/UGATIT-pytorch/dataset.py", line 1, in <module> import torch.utils.data as data ImportError: No module named torch.utils.data

    opened by IMakiMaki 2
  • RuntimeError: CUDA error: out of memory

    RuntimeError: CUDA error: out of memory

    run: python main.py --dataset my_dataset --light True error: RuntimeError: CUDA error: out of memory

    I had sucessfully installed pytorch with GPU on computer.


    import torch torch.cuda.is_available() True


    This works well,and I find no error when running other pytorch codes.

    opened by guangzhao17 2
  • Rho parameter in AdaILN and ILN

    Rho parameter in AdaILN and ILN

    Hi, I have noticed that the parameter Rho of AdaILN and ILN layer in pytorch version of UGATIT is not clipped or constrainted compared to your TF version and the function in paper.

    opened by Trueyellow 2
  • CAM loss incorrect?

    CAM loss incorrect?

    Hi, in the paper, I find $L_{cam}^{D_{t}}$ have a log function, but in source code, only use MSE(UGATIT.py 182-189 lines). So, the paper adds unnecessarily log?

    opened by FangYang970206 1
  • Wrong Instance/Layer norm evaluation

    Wrong Instance/Layer norm evaluation

    It seems like your implementation of AdaILN/ILN layer in pytorch significantly differs from tf version (actually, tf version is the correct one).

    in_mean, in_var = torch.mean(torch.mean(input, dim=2, keepdim=True), dim=3, keepdim=True), torch.var(torch.var(input, dim=2, keepdim=True), dim=3, keepdim=True)
    ln_mean, ln_var = torch.mean(torch.mean(torch.mean(input, dim=1, keepdim=True), dim=2, keepdim=True), dim=3, keepdim=True), torch.var(torch.var(torch.var(input, dim=1, keepdim=True), dim=2, keepdim=True), dim=3, keepdim=True)
    

    This block implies that when you are trying to evaluate variance of each tensor in the batch over appropriate dimension, instead of variation over axes [2, 3] in IN and axes [1, 2, 3] in LN you evaluate variation of variation in IN and variation of variation of variation in LN which is wrong

    opened by kefirski 1
  • No shortcut connection in ResnetAdaILNBlock (compared to tf version)

    No shortcut connection in ResnetAdaILNBlock (compared to tf version)

    Hi, thank you for sharing source code.

    But, compared to tf version, ResNetAdaILNBlock layer doesn't seem to have a shortcut connection which adds the input of layer to output directory.

    opened by SerialLain3170 1
  • Unstable compared to tensorflow version

    Unstable compared to tensorflow version

    Hi, I found that the pytorch version is more unstable compared to tensorflow version of UGATIT. One difference I noticed in this version is the weight-decay is not used in the pytorch optimizer compared to TF version.

    opened by Trueyellow 1
  • fix to issue #23 (CUDA out of memory at 1000th epoch) as suggested by…

    fix to issue #23 (CUDA out of memory at 1000th epoch) as suggested by…

    Fix to issue #23 (CUDA out of memory at 1000th epoch) as suggested by @07hyx06. Surrounded print output with torch.no_grad().

    Tested by running on an internal large dataset. Before the fix, it stopped at 1000th epoch, complaining that it was out of memory. After fix, it's still running at 128,000 epochs. Memory initially 22157MB on GPU, and has not increased during training.

    opened by wilsonjwcsu 0
  • Weight initialization not found in this repo

    Weight initialization not found in this repo

    According to the appendix section B.2 in the paper, the weights should be initialized from a zero-centered normal distribution with a standard deviation of 0.02. But I did not find this part in the repo. Could anybody explain?

    opened by zihaog0724 0
  • Testing does not work!

    Testing does not work!

    When calling python main.py --dataset maps --light True --phase test the model seems to fail to load the checkpoint weights. Any Idea what could be the problem?

    Last output:

    ...
    
    ##### Weight #####
    # adv_weight :  1
    # cycle_weight :  10
    # identity_weight :  10
    # cam_weight :  1000
     [*] Load FAILURE
     [*] Test finished!
    All done!
    

    My folder structure:

    ├── dataset
    │   ├── maps
    │   │   ├── testA
    │   │   ├── testB
    │   │   ├── trainA
    │   │   ├── trainB
    │   │   └── valB
    
    opened by Lauenburg 0
Owner
Hyeonwoo Kang
Hyeonwoo Kang
[CVPR 2021] Region-aware Adaptive Instance Normalization for Image Harmonization

RainNet — Official Pytorch Implementation Region-aware Adaptive Instance Normalization for Image Harmonization Jun Ling, Han Xue, Li Song*, Rong Xie,

null 130 Dec 11, 2022
Pytorch implementation of the paper "Enhancing Content Preservation in Text Style Transfer Using Reverse Attention and Conditional Layer Normalization"

Pytorch implementation of the paper "Enhancing Content Preservation in Text Style Transfer Using Reverse Attention and Conditional Layer Normalization"

Dongkyu Lee 4 Sep 18, 2022
pytorch implementation of "Contrastive Multiview Coding", "Momentum Contrast for Unsupervised Visual Representation Learning", and "Unsupervised Feature Learning via Non-Parametric Instance-level Discrimination"

Unofficial implementation: MoCo: Momentum Contrast for Unsupervised Visual Representation Learning (Paper) InsDis: Unsupervised Feature Learning via N

Zhiqiang Shen 16 Nov 4, 2020
Code for "On the Effects of Batch and Weight Normalization in Generative Adversarial Networks"

Note: this repo has been discontinued, please check code for newer version of the paper here Weight Normalized GAN Code for the paper "On the Effects

Sitao Xiang 182 Sep 6, 2021
IAST: Instance Adaptive Self-training for Unsupervised Domain Adaptation (ECCV 2020)

This repo is the official implementation of our paper "Instance Adaptive Self-training for Unsupervised Domain Adaptation". The purpose of this repo is to better communicate with you and respond to your questions. This repo is almost the same with Another-Version, and you can also refer to that version.

CVSM Group -  email: czhu@bupt.edu.cn 84 Dec 12, 2022
HINet: Half Instance Normalization Network for Image Restoration

HINet: Half Instance Normalization Network for Image Restoration Liangyu Chen, Xin Lu, Jie Zhang, Xiaojie Chu, Chengpeng Chen Paper: https://arxiv.org

null 303 Dec 31, 2022
Half Instance Normalization Network for Image Restoration

HINet Half Instance Normalization Network for Image Restoration, based on https://github.com/megvii-model/HINet. Dependencies NumPy PyTorch, preferabl

Holy Wu 4 Jun 6, 2022
PyTorch implementation of Lip to Speech Synthesis with Visual Context Attentional GAN (NeurIPS2021)

Lip to Speech Synthesis with Visual Context Attentional GAN This repository contains the PyTorch implementation of the following paper: Lip to Speech

null 6 Nov 2, 2022
This is the official pytorch implementation for the paper: Instance Similarity Learning for Unsupervised Feature Representation.

ISL This is the official pytorch implementation for the paper: Instance Similarity Learning for Unsupervised Feature Representation, which is accepted

null 19 May 4, 2022
Towards Ultra-Resolution Neural Style Transfer via Thumbnail Instance Normalization

Towards Ultra-Resolution Neural Style Transfer via Thumbnail Instance Normalization Official PyTorch implementation for our URST (Ultra-Resolution Sty

czczup 148 Dec 27, 2022
The pytorch implementation of DG-Font: Deformable Generative Networks for Unsupervised Font Generation

DG-Font: Deformable Generative Networks for Unsupervised Font Generation The source code for 'DG-Font: Deformable Generative Networks for Unsupervised

null 130 Dec 5, 2022
Spatially-Adaptive Pixelwise Networks for Fast Image Translation, CVPR 2021

Image Translation with ASAPNets Spatially-Adaptive Pixelwise Networks for Fast Image Translation, CVPR 2021 Webpage | Paper | Video Installation insta

Tamar Rott Shaham 100 Dec 28, 2022
Minimal PyTorch implementation of Generative Latent Optimization from the paper "Optimizing the Latent Space of Generative Networks"

Minimal PyTorch implementation of Generative Latent Optimization This is a reimplementation of the paper Piotr Bojanowski, Armand Joulin, David Lopez-

Thomas Neumann 117 Nov 27, 2022
CoaT: Co-Scale Conv-Attentional Image Transformers

CoaT: Co-Scale Conv-Attentional Image Transformers Introduction This repository contains the official code and pretrained models for CoaT: Co-Scale Co

mlpc-ucsd 191 Dec 3, 2022
Official PyTorch implementation of "VITON-HD: High-Resolution Virtual Try-On via Misalignment-Aware Normalization" (CVPR 2021)

VITON-HD — Official PyTorch Implementation VITON-HD: High-Resolution Virtual Try-On via Misalignment-Aware Normalization Seunghwan Choi*1, Sunghyun Pa

Seunghwan Choi 250 Jan 6, 2023
Official implementation of "DSP: Dual Soft-Paste for Unsupervised Domain Adaptive Semantic Segmentation"

DSP Official implementation of "DSP: Dual Soft-Paste for Unsupervised Domain Adaptive Semantic Segmentation". Accepted by ACM Multimedia 2021. Authors

null 20 Oct 24, 2022
Attentional Focus Modulates Automatic Finger‑tapping Movements

"Attentional Focus Modulates Automatic Finger‑tapping Movements", in Scientific Reports

Xingxun Jiang 1 Dec 2, 2021
Super Pix Adv - Offical implemention of Robust Superpixel-Guided Attentional Adversarial Attack (CVPR2020)

Super_Pix_Adv Offical implemention of Robust Superpixel-Guided Attentional Adver

DLight 8 Oct 26, 2022
PyTorch implementation of "Image-to-Image Translation Using Conditional Adversarial Networks".

pix2pix-pytorch PyTorch implementation of Image-to-Image Translation Using Conditional Adversarial Networks. Based on pix2pix by Phillip Isola et al.

mrzhu 383 Dec 17, 2022