Giter VIP home page Giter VIP logo

ugatit-pytorch's Introduction

U-GAT-IT — Official PyTorch Implementation

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

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

ugatit-pytorch's People

Contributors

trueyellow avatar znxlwm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ugatit-pytorch's Issues

test error

error imfoemation:number of epochs must be larger than or equal to one.

CUDA out of memory (with light flag)

Hi guys!
I'm using RTX 2080Ti 11GB. At first I tried to train on a dataset of 100K images (1000px) with --light flag . And after the 1000th epoch I got the "CUDA out of memory" error. Then I tried a smaller dataset of 10K images (256px) and got the same error after the 1000th epoch. Finally I tried 3400 images (256px) and there were no changes.

Here is an output:

[  997/1000000] time: 582.6236 d_loss: 0.00474171, g_loss: 1344.68078613
[  998/1000000] time: 583.2094 d_loss: 0.00624988, g_loss: 1328.24572754
[  999/1000000] time: 583.7950 d_loss: 0.00641153, g_loss: 1374.71826172
[ 1000/1000000] time: 584.3810 d_loss: 0.00178387, g_loss: 1280.08032227
/home/p0wx/prj/UGATIT-pytorch/utils.py:46: RuntimeWarning: invalid value encountered in true_divide
  cam_img = x / np.max(x)
Traceback (most recent call last):
  File "main.py", line 83, in <module>
    main()
  File "main.py", line 75, in main
    gan.train()
  File "/home/p0wx/prj/UGATIT-pytorch/UGATIT.py", line 209, in train
    fake_B2B, fake_B2B_cam_logit, _ = self.genA2B(real_B)
  File "/home/p0wx/.local/share/virtualenvs/p0wx-AcgHNkMk/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in call
    result = self.forward(*input, **kwargs)
  File "/home/p0wx/prj/UGATIT-pytorch/networks.py", line 108, in forward
    out = self.UpBlock2(x)
  File "/home/p0wx/.local/share/virtualenvs/p0wx-AcgHNkMk/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in call
    result = self.forward(*input, **kwargs)
  File "/home/p0wx/.local/share/virtualenvs/p0wx-AcgHNkMk/lib/python3.6/site-packages/torch/nn/modules/container.py", line 92, in forward
    input = module(input)
  File "/home/p0wx/.local/share/virtualenvs/p0wx-AcgHNkMk/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in call
    result = self.forward(*input, **kwargs)
  File "/home/p0wx/prj/UGATIT-pytorch/networks.py", line 191, in forward
    out = self.rho.expand(input.shape[0], -1, -1, -1) * out_in + (1-self.rho.expand(input.shape[0], -1, -1, -1)) * out_ln
RuntimeError: CUDA out of memory. Tried to allocate 16.00 MiB (GPU 0; 10.76 GiB total capacity; 9.32 GiB already allocated; 5.56 MiB free; 621.27 MiB cached)```

How large GPU memory can hold the entire network

I tried to train your complete network under the nvidia GTX 1080Ti with 12G GPU memory.
But pytorch throw out a "out of cuda memory" error.
I just wonder how large gpu memory i have i can train the so big network?

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?

How to understand the CAM loss for the generator including fake_B2A and fake_A2A?

G_cam_loss_A = self.BCE_loss(fake_B2A_cam_logit, torch.ones_like(fake_B2A_cam_logit).to(self.device)) + self.BCE_loss(fake_A2A_cam_logit, torch.zeros_like(fake_A2A_cam_logit).to(self.device))
G_cam_loss_B = self.BCE_loss(fake_A2B_cam_logit, torch.ones_like(fake_A2B_cam_logit).to(self.device)) + self.BCE_loss(fake_B2B_cam_logit, torch.zeros_like(fake_B2B_cam_logit).to(self.device))

As for the generator, what does the cam want to classify?
Classify the real image to 0? Classify the fake image to 1?


As for the discriminator, we can see that the real images will be classified to 1 and the fake images will be classified to 0.
Therefore, I am confusing about the CAM for the generator.

UGATIT 预训练模型和数据集百度云下载,为方便谷歌硬盘无法使用的人,不懂的可加Q群857449786 注明UGATIT 共同研究 ,谢谢! 官方已经开放的数据集和模型在google硬盘,比较大,可能无法下载,我分卷压缩了一下,分享到百度云,方便大家下载。

UGATIT 预训练模型和数据集百度云下载,为方便谷歌硬盘无法使用的人,不懂的可加Q群857449786 注明UGATIT 共同研究 ,谢谢!

官方已经开放的数据集和模型在google硬盘,比较大,可能无法下载,我分卷压缩了一下,分享到百度云,方便大家下载。
Pretrained model: selfie2anime checkpoint (100 epoch)
Dataset:selfie2anime dataset

目前win10下的测试训练自己的数据问题,都可以 ,UGATIT 预训练模型和数据集百度云下载,为方便谷歌硬盘无法使用的人,不懂的可加Q群857449786 注明UGATIT 共同研究 ,谢谢!

链接:https://pan.baidu.com/s/1dP1mXuU-rA9dPvFe8YS8jQ
提取码:k6rc
QQ截图20190816225316

下载后合并01.02.03为一个文件。
目录结构如下:
B:\Tensorflow\UGATIT\checkpoint\UGATIT_selfie2anime_lsgan_4resblock_6dis_1_1_10_10_1000_sn_smoothing
QQ截图20190819095152
QQ截图20190819095233

unbalance loss

with the default config, i got 5.x gen_loss but got 1000.x dis_loss. Can you give me some tweak to balance it

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.

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)

[tensorflow] Allocation exceeds 10% of system memory

Not quite sure what I am writing for the intended purpose. The fact is that I have no practical experience with python and areas devoted to machine learning. Quite by chance I read about your work and decided to deploy the code on my machine (OS Ubuntu 19.04). The test (python3 main.py --dataset selfie2anime --phase test) results in the specified error. A fragment of the console log:

[*] Reading checkpoints ...
W0826 19: 42: 05.169215 140086150489920 deprecation.py:323] From /home/praetorp/.local/lib/python3.7/site-packages/tensorflow/python/training/saver.py:1276: checkpoint_exists (from tensorflow.python .training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to check for files with this prefix.
2019-08-26 19: 42: 05.310732: W tensorflow / core / framework / allocator.cc: 107] Allocation of 1073741824 exceeds 10% of system memory.
2019-08-26 19: 42: 05.310732: W tensorflow / core / framework / allocator.cc: 107] Allocation of 1073741824 exceeds 10% of system memory.
2019-08-26 19: 42: 05.311256: W tensorflow / core / framework / op_kernel.cc: 1502] OP_REQUIRES failed at save_restore_v2_ops.cc:184: Out of range: Read less bytes than requested

I would be grateful if you could help me figure this out.

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

Error during test: local variable 'A2B' referenced before assignment

I could successfully train the model on my own dataset, and I can see that the trained models are saved in the model folder already. However, I got the following error when I ran test code "python main.py --dataset experiment1 --phase test --light True". Do you know where might go wrong?
Thanks!
The error is:
'''
[*] Load SUCCESS
Traceback (most recent call last):
File "main.py", line 83, in
main()
File "main.py", line 79, in main
gan.test()
File "/home/zoey/nas/zoey/github/UGATIT-pytorch/UGATIT.py", line 387, in test
A2B = np.concatenate((A2B, np.concatenate((RGB2BGR(tensor2numpy(denorm(real_A[0]))),
UnboundLocalError: local variable 'A2B' referenced before assignment
'''

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

var(): argument 'dim' must be int, not list

torch.mean(input, dim=[2, 3], keepdim=True), torch.var(input, dim=[2, 3], keepdim=True)

Modify the code so that it resembles the following code sample:

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)

No activation between residual blocks

There's neither relu before the first conv

nn.Conv2d(dim, dim, kernel_size=3, stride=1, padding=0, bias=use_bias),
nor after addition
out = x + self.conv_block(x)
in the residual blocks, i.e., there're no activations between neighboring residual bocks.

I failed to find design details of residual blocks from the paper, but I guess it's a bug, can you confirm? Thanks.

PS: Just checked the official tf code, it suffers from the same problem.

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.

light flag is not working?

I ran python main.py --dataset selfie2anime --light True but I have this error

AssertionError: Torch not compiled with CUDA enabled

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

Why using up-pooling instead of 2 stride convtranspose when UP

Hey professor. I remember that the 2 stride conv is more stable than up-pooling (according to DCGAN). However, in your model, the downsampling part is 2 stride conv, while up-pooling in upsampling part.

Could you give us a reason for this?
Looking forward to your reply

Explicit initialization step

Is it possible that there is no explicit initialization for the created models? I cannot find it in UGATIT.py file or anywhere else. I would be grateful if you refer me to it or explain its absence.

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.

Different setting of bias

Hi, here is another issue that, the TF version of UGATIT has bias in most of the layers (including Linear and Conv), but the torch version has no bias at all.
Just wondering, if there is any difference?

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!

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.