Giter VIP home page Giter VIP logo

tunit's Introduction

Rethinking the Truly Unsupervised Image-to-Image Translation
(ICCV 2021)

teaser

Each image is generated with the source image in the left and the average style vector of each cluster. The network is trained under fully unsupervised manner.

Official pytorch implementation of "Rethinking the Truly Unsupervised Image-to-Image Translation"

Rethinking the Truly Unsupervised Image-to-Image Translation
Kyungjune Baek1*, Yunjey Choi2, Youngjung Uh1, Jaejun Yoo3, Hyunjung Shim1
* Work done during his internship at Clova AI Research
1 Yonsei University
2 NAVER AI Lab.
3 UNIST

Absract Every recent image-to-image translation model inherently requires either image-level (i.e. input-output pairs) or set-level (i.e. domain labels) supervision. However, even set-level supervision can be a severe bottleneck for data collection in practice. In this paper, we tackle image-to-image translation in a fully unsupervised setting, i.e., neither paired images nor domain labels. To this end, we propose a truly unsupervised image-to-image translation model (TUNIT) that simultaneously learns to separate image domains and translates input images into the estimated domains. Experimental results show that our model achieves comparable or even better performance than the set-level supervised model trained with full labels, generalizes well on various datasets, and is robust against the choice of hyperparameters (e.g. the preset number of pseudo domains). Furthermore, TUNIT can be easily extended to semi-supervised learning with a few labeled data.

Requirement

Library

pip install -r requirements.txt

* pytorch==1.1.0 or 1.2.0  
* tqdm  
* opencv-python  
* scipy  
* sklearn
* matplotlib  
* pillow  
* tensorboardX 

Dataset

Project
|--- tunit
|          |--- main.py
|          |--- train
|                 |--- train_unsupervised.py
|                 |--- ...
|
|--- data
       |--- afhq
             |--- train
             |--- test
       |--- animal_faces
             |--- n02085620
             |--- n02085782
             |--- ...
       |--- ffhq
             |--- images
                    |--- 000001.jpg
                    |--- ...
       |--- lsun_car
             |--- images
                    |--- 000001.jpg
                    |--- ...

Then, call --data_path='../data'

Hardware

  • This source code is mainly tested on V100 and P40.

How to Run (Quick Start)

After setting the dataset directory, the code can be easily run by the scripts below.

Train on local

Supervised
python main.py --gpu $GPU_TO_USE --p_semi 1.0 --dataset animal_faces --data_path='../data'

Semi-supervised
python main.py --gpu $GPU_TO_USE --p_semi 0.5 --dataset animal_faces --data_path='../data'

Unsupervised
python main.py --gpu $GPU_TO_USE --p_semi 0.0 --dataset animal_faces --data_path='../data'

Test on local

python main.py --gpu $GPU_TO_USE --validation --load_model $DIR_TO_LOAD --dataset animal_faces

Monitoring

tensorboard --logdir=$DIR/events --port=$PORT

Actual example

Train
python main.py --gpu 0 --dataset animal_faces --output_k 10 --data_path '../data' --p_semi 0.0
python main.py --gpu 0 --dataset animal_faces --output_k 10 --data_path '../data' --p_semi 0.2
python main.py --gpu 0 --dataset afhq_cat --output_k 10 --data_path '../data' --p_semi 0.0
python main.py --gpu 1 --dataset animal_faces --data_path '../data' --p_semi 1.0
python main.py --gpu 0,1 --dataset summer2winter --output_k 2 --data_path '../data' --p_semi 0.0 --img_size 256 --batch_size 16 --ddp

Test
python main.py --gpu 0 --dataset animal_faces --output_k 10 --data_path '../data' --validation --load_model GAN_20190101_101010
python main.py --gpu 1 --dataset afhq_cat --output_k 10 --data_path '../data' --validation --load_model GAN_20190101_101010
python main.py --gpu 2 --dataset summer2winter --output_k 2 --data_path '../data' --validation --load_model GAN_20190101_101010

Monitoring - open terminal at ./tunit/logs
tensorboard --logdir=./GAN_20200101_101010/events

Pretrained Model

Download

One Drive

  • Download folders to load, then place the folder under 'logs'.
  • Links of google drive are deprecated.
Project
|--- tunit
|          |--- main.py
|          |--- logs
|                 |--- animalFaces10_0_00
|                               |--- checkpoint.txt
|                               |--- model_4568.ckpt
|          |--- train
|                 |--- train_unsupervised.py
|                 |--- ...

Then, RUN
python main.py --gpu 0 --dataset animal_faces --output_k 10 --img_size 128 --data_path $DATAPATH --validation --load_model animalFaces10_0_00 --p_semi 0.0

How to run

AFHQ Cat
python main.py --gpu 0 --dataset afhq_cat --output_k 10 --img_size 128 --data_path $DATAPATH --validation --load_model afhq_cat_128
python main.py --gpu 0 --dataset afhq_cat --output_k 10 --img_size 256 --data_path $DATAPATH --validation --load_model afhq_cat_256
AFHQ Dog
python main.py --gpu 0 --dataset afhq_dog --output_k 10 --img_size 128 --data_path $DATAPATH --validation --load_model afhq_dog_128
python main.py --gpu 0 --dataset afhq_dog --output_k 10 --img_size 256 --data_path $DATAPATH --validation --load_model afhq_dog_256

AFHQ Wild
python main.py --gpu 0 --dataset afhq_wild --output_k 10 --img_size 128 --data_path $DATAPATH --validation --load_model afhq_wild_128
python main.py --gpu 0 --dataset afhq_wild --output_k 10 --img_size 256 --data_path $DATAPATH --validation --load_model afhq_wild_256
AnimalFaces-10
python main.py --gpu 0 --dataset animal_faces --output_k 10 --img_size 128 --data_path $DATAPATH --validation --load_model animalFaces10_0_00 --p_semi 0.0
python main.py --gpu 0 --dataset animal_faces --output_k 10 --img_size 128 --data_path $DATAPATH --validation --load_model animalFaces10_0_20 --p_semi 0.2

Explanation for codes

The validation generates 200 images per args.iters iterations. To reduce the number of images, please adjust the validation frequency. The checkpoint file is saved per ((args.epochs//10) * args.iters) iterations. Or comment out validation.py#L81 to validation.py#L162.

  • For more classes on AnimalFaces, change the list at main.py#L227 then, set args.output_k to len(args.att_to_use)
    • ex) args.att_to_use = [i for i in range(100)] then, run: python main.py --output_k 100 ...

Arguments

  • batch_size, img_size, data_path and p_semi are frequently speified.
  • Please refer "help" of the arguments in main.py.

Code Structure

  • main.py
    • Execute main.py to run the codes.
    • The script builds networks, optimizers and data loaders, and manages the checkpoint files.
  • datasets
    • custom_dataset.py
      • Basically, it is the same as ImageFolder but contains remap procedure of class numbers.
    • datasetgetter.py
      • Returns dataset instance of the dataset specified by args.dataset.
      • The instance returns original image, transformed image and its ground truth label.
  • models
    • blocks.py
      • Blocks for building networks.
      • This code is based on FUNIT repos.
    • guidingNet.py
      • Definition of guiding network.
    • discriminator.py
      • Definition of discriminator.
      • The architecture is based on StarGANv2, but it contains two residual blocks for each resolution.
    • generator.py
      • Definition of generator.
      • It consists of decoder, content encoder and MLP for AdaIN.
      • This code is from FUNIT repos.
  • train
    • train_unsupervised.py
      • It is called by setting --p_semi to 0.0
      • This mode does not utilize the labels at all.
    • train_supervised.py
      • It is called by setting --p_semi to 1.0
      • This mode fully utilizes the labels.
    • train_semisupervised.py
      • It is called by setting --p_semi between 0.0 to 1.0.
      • This mode utilizes (--p_semi * 100)% labels.
  • validation
    • cluster_eval.py
    • eval_metrics.py
      • These two scripts contain the functions for evaluating the classification performance.
      • These are from IIC repos.
    • plot_tsne.py (can be removed)
      • For plotting t-SNE.
    • validation.py
      • Generate fake samples and calculate FID.
  • tools
    • utils.py
      • Functions and class for logger, make folders, averageMeter and add logs.
    • ops.py
      • Queue operation and loss functions.
  • resrc
    • For image files of README.md

You can change the adversarial loss by modifying calc_adv_loss in ops.py. For the different strategy of training, please refer the files in train.

Results

afhq_cat afhq_dog afhq_wild ffhq lsun

Each image is generated with the source image in left and the average vector of reference images. The network is trained under fully unsupervised manner.

License

TUNIT is distributed under MIT unless the header specifies another license.

Copyright (c) 2020-present NAVER Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORTd OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

The pretrained models is covered by Creative Commons BY-NC 4.0 license by NAVER Corporation. You can use, copy, tranform and build upon the material for non-commercial purposes as long as you give appropriate credit by citing our paper, and indicate if changes were made.

Citation

If you find this work useful for your research, please cite our paper:

@InProceedings{Baek_2021_ICCV,
    author    = {Baek, Kyungjune and Choi, Yunjey and Uh, Youngjung and Yoo, Jaejun and Shim, Hyunjung},
    title     = {Rethinking the Truly Unsupervised Image-to-Image Translation},
    booktitle = {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
    month     = {October},
    year      = {2021},
    pages     = {14154-14163}
}

tunit's People

Contributors

clovaaiadmin avatar friedronaldo avatar yunjey 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

tunit's Issues

AdaIN

hi,FriedRonaldo
in your code , the weight and the bias of the 'AdaIN' layer is from the Fully connected
example : 128-style code ---FC----> 256 ----FC----> 2feature_num
the bias and weight are get from the "2
feature_num"
can i use the 128-style code to comput mu and sigma, and then comput the 'AdaIN' layer ?
example : mu = mean(128-style code) sigma = variance(128-style code)
what is the difference?

Training Discriminator vs Generator in TUNIT

Could you please explain that why the gradients of d_adv_real, d_gp, and d_adv_fake are calculated separately when training the Discriminator? Whereas in G only the summation of all loses i.e. g_loss is used for calculating the gradients?

I am referring to the following section of code.

d_opt.zero_grad()
d_adv_real.backward(retain_graph=True)
d_gp.backward()
d_adv_fake.backward()
if args.distributed:
average_gradients(D)
d_opt.step()

issue when loading a checkpoint file

Hi, I used the following code load the checkpoint:

G = DataParallel(Generator(img_size=512,sty_dim=128))
C = DataParallel(GuidingNet(128))
load_file = "./ologs/GAN_20200630-174700/model_42.ckpt"
checkpoint = torch.load(load_file, map_location="cuda:0")
G.load_state_dict(checkpoint["G_EMA_state_dict"]) #G_EMA_state_dict
C.load_state_dict(checkpoint['C_EMA_state_dict'])
G.to(device="cuda")
C.to(device="cuda")
G.eval()
C.eval()
c_src = G.cnt_encoder(x_src)
s_ref = C.moco(x_ref)
x_res = G.decode(c_src, s_ref)

i am getting the following error:
AttributeError: 'DataParallel' object has no attribute 'cnt_encoder'

since i don't have great experience with pytorch i am not able to figure how to actually load without dataparallel. let me know how i can solve and run the inference part,
Thanks

afhq dataset error

Hi,when I use your actual example in Train:
python main.py --gpu 0 --dataset afhq_cat --output_k 10 --data_path '../data' --p_semi 0.2

will have error.

Traceback (most recent call last):
File "main.py", line 524, in
main()
File "main.py", line 201, in main
main_worker(args.gpu, ngpus_per_node, args)
File "main.py", line 257, in main_worker
train_loader, val_loader, train_sampler = get_loader(args, {'train': train_dataset, 'val': val_dataset})
File "main.py", line 448, in get_loader
train_sup_dataset = train_dataset['SUP']
KeyError: 'SUP'

Is the code fit for all the dataset? and What's the reason you deal different dataset with different way?
Thanks

Why updating the gradients of the guiding network C while training G?

Hi. I couldn't find the explanation of the following question on your paper.

While training the Generator, could you please explain why you update the gradients of the guiding network C? (

c_opt.zero_grad()
g_loss.backward()
if args.distributed:
average_gradients(G)
average_gradients(C)
c_opt.step()
g_opt.step()
) Even though we are not backpropagating for the guiding network?

Can TUNIT do few-shot generation?

I was wondering that have you tried using TUNIT for the few-shot generation task like FUNIT?

Given few images of an unseen class, can TUNIT transfer its style (from the guiding network) to a seen content during inference?
OR
it will require fine-tuning the network on the new class?

summer2winter dataset not producing results

I have two folder summer and winter and i have modified dataset structure as per guidelines(like animal_faces), I started supervised approach since I have proper labelled dataset, after the successful completion of training for 200 epochs the results are same as original input image with some noises added to it. not sure where the things are going wrong. how to solve this??

Validation Error?

Hi,sorry to bother you
But I use the validation coda to validate my training model
"python main.py --gpu 3 --validation --load_model GAN_20210928-031155 --dataset animal_faces --data_path 'data'"
but it get totally error result.

It gather the all 50 val dataset to one class
I draw the TSNE,it seems like that
微信图片_20211004165459
and print " (i, len(cluster_grid[i]), cluster_map[i]) " it shows that:
0 0 0
1 500 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 0 0
9 0 0

and the results are nothing changed.
Do you know the reason?

微信图片_20211004165607

Error while training afhq_wild; RuntimeError: unsupported operation: more than one element of the written-to tensor refers to a single memory (assert_no_internal_overlap at /pytorch/aten/src/ATen/MemoryOverlap.cpp:36)

Please find the stacktrace below. Can you let me know what I am doing wrong?

>>> python main.py --dataset afhq_wild --output_k 10 --data_path '/home/yyr/data/' --p_semi 0.0 --img_size 64 --batch_size 32   
PYTORCH VERSION 1.5.0
main.py:146: UserWarning: You have chosen a specific GPU. This will completely disable data parallelism.
  warnings.warn('You have chosen a specific GPU. This will completely '
False
False
MULTIPROCESSING DISTRIBUTED :  False
Use GPU: 0 for training
Init Generator
GENERATOR NF :  64
Init ContentEncoder
Init Decoder
Init Generator
GENERATOR NF :  64
Init ContentEncoder
Init Decoder
USE CLASSES [2]
LABEL MAP: {2: 0}
USE AFHQ dataset [FOR IIC]
LABEL MAP: {2: 0}
500
dataset                            afhq_wild           

data_path                          /home/yyr/data/     

workers                            4                   

model_name                         GAN_20200617-194923 

epochs                             200                 

iters                              1000                

batch_size                         32                  

val_batch                          10                  

log_step                           100                 

sty_dim                            128                 

output_k                           10                  

img_size                           64                  

dims                               2048                

p_semi                             0.0                 

load_model                         None                

validation                         False               

world_size                         1                   

rank                               0                   

gpu                                0                   

ddp                                False               

port                               8989                

iid_mode                           iid+                

w_gp                               10.0                

w_rec                              0.1                 

w_adv                              1.0                 

w_vec                              0.01                

data_dir                           /home/yyr/data/     

start_epoch                        0                   

train_mode                         GAN_UNSUP           

unsup_start                        0                   

separated                          65                  

ema_start                          66                  

fid_start                          66                  

multiprocessing_distributed        False               

distributed                        False               

ngpus_per_node                     1                   

log_dir                            ./logs/GAN_20200617-194923

event_dir                          ./logs/GAN_20200617-194923/events

res_dir                            ./results/GAN_20200617-194923

num_cls                            10                  

att_to_use                         [2]                 

epoch_acc                          []                  

epoch_avg_subhead_acc              []                  

epoch_stats                        []                  

to_train                           CDGI                

min_data                           4738                

max_data                           4738                

START EPOCH[1]
  0%|                                                  | 0/1000 [00:00<?, ?it/s]Traceback (most recent call last):
  File "main.py", line 524, in <module>
    main()
  File "main.py", line 201, in main
    main_worker(args.gpu, ngpus_per_node, args)
  File "main.py", line 305, in main_worker
    trainFunc(train_loader, networks, opts, epoch, args, {'logger': logger, 'queue': queue})
  File "/home/yyr/Documents/github/tunit/train/train_unsupervised.py", line 103, in trainGAN_UNSUP
    c_loss.backward()
  File "/home/yyr/anaconda3/lib/python3.7/site-packages/torch/tensor.py", line 198, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File "/home/yyr/anaconda3/lib/python3.7/site-packages/torch/autograd/__init__.py", line 100, in backward
    allow_unreachable=True)  # allow_unreachable flag
RuntimeError: unsupported operation: more than one element of the written-to tensor refers to a single memory location. Please clone() the tensor before performing the operation. (assert_no_internal_overlap at /pytorch/aten/src/ATen/MemoryOverlap.cpp:36)
frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x46 (0x7fc7ed454536 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libc10.so)
frame #1: at::assert_no_internal_overlap(c10::TensorImpl*) + 0xc5 (0x7fc82a771d55 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #2: at::TensorIterator::check_mem_overlaps() + 0x71 (0x7fc82ab6e8a1 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #3: at::TensorIterator::build() + 0x2c (0x7fc82ab77b4c in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #4: <unknown function> + 0xbb3718 (0x7fc82a8ed718 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #5: at::native::copy_(at::Tensor&, at::Tensor const&, bool) + 0x44 (0x7fc82a8ef224 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #6: <unknown function> + 0x316ec4d (0x7fc82cea8c4d in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #7: torch::autograd::CopySlices::apply(std::vector<at::Tensor, std::allocator<at::Tensor> >&&) + 0xb35 (0x7fc82caced65 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #8: <unknown function> + 0x2d89c05 (0x7fc82cac3c05 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #9: torch::autograd::Engine::evaluate_function(std::shared_ptr<torch::autograd::GraphTask>&, torch::autograd::Node*, torch::autograd::InputBuffer&) + 0x16f3 (0x7fc82cac0f03 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #10: torch::autograd::Engine::thread_main(std::shared_ptr<torch::autograd::GraphTask> const&, bool) + 0x3d2 (0x7fc82cac1ce2 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #11: torch::autograd::Engine::thread_init(int) + 0x39 (0x7fc82caba359 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #12: torch::autograd::python::PythonEngine::thread_init(int) + 0x38 (0x7fc8391f9998 in /home/yyr/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
frame #13: <unknown function> + 0xd6cb4 (0x7fc83a0e7cb4 in /lib/x86_64-linux-gnu/libstdc++.so.6)
frame #14: <unknown function> + 0x9609 (0x7fc83c549609 in /lib/x86_64-linux-gnu/libpthread.so.0)
frame #15: clone + 0x43 (0x7fc83c470103 in /lib/x86_64-linux-gnu/libc.so.6)

  0%|                                                  | 0/1000 [00:00<?, ?it/s]

the number of the reference image

the example in paper shows that four reference images are used to extract the average style code. but in code,only one reference image is used.

pretarined food10 weights

Hello.

Do you have any plan to upload other pre-trained weights of another setting that were used in your paper?

Unless can you upload only trained food10 weights of which the number of domain is 10.

Thanks.

About Food-10 dataset settings

HI,sorry to bother you.
But I have some questions when I try to reproduce the quantitive result in Food -10 dataset.
I add the food-10 dataset in code and use the same settings as 'animal faces' dataset.

When I run the code of 'animal faces'.I can get the best mFID:49.1 when paper gave the mFID as 47.7.
But when I run the code of 'food-10'.I can get the best mFID:69.50 when paper gave the mFID as 52.2
I use pytorch 1.9.0.
I think the difference mFID between animal faces is reasonable.But the 'food-10' is strange.
So I am wondering that if you use different settings in 'food-10' dataset?
Thanks

Why the argumentation transform of the orginal image contains colorjitter

Hi, thanks for sharing your code.
I have several questions about your design choice and looking forward to your reply.

  1. Data augmentation:
    I find the augmentation operation contains

transforms.ColorJitter(0.4, 0.4, 0.4, 0.125) operation.

Since the style information always includes the color, why you involve the ColorJitter operation and regard this transformation sample as the positive sample of the original image?
Will that influence the final results?

  1. queue samples use the transformed image
    You use
    x_k = data[1]

    in def initialize_queue(model_k, device, train_loader, feat_size=128)
    This means you use a transformed image to extract style vector rather than the original image, why?

Looking forward to your reply, thanks!

D and G losses are 0s

Hi so far i started training using

python main.py --dataset afhq_wild --output_k 10 --data_path '/home/yyr/data/' --p_semi 0.0 --img_size 128 --batch_size 16

But even at 10th epoch D and G have 0 losses. Is this expected or abnormal?
Epoch: [10/200] [500/1000] MODE[ONLYCLS] Avg Loss: D[0.00] G[0.00] C[2.61]

I am not seeing any items in the corresponding results folder for the run even after 9 epochs.... At what point does it give results?

Average style vectors?

In Figure 17 (a), style vectors are averaged for domain translation. I tried to find this in your code but haven't found yet. Could you please let me know the code where you have done this? or how to generate averaged style vector translated images?

FFHQ results

Hello :)

I have a question about figure 4. in this paper.

In the paper, the ffhq results were generated by using averaged style vectors of each domain.

However, I checked that the style vector is generated globally. There is only one style vector that is shared by all the domains.

Could you explain about "averaged style vectors of each domain"?

Thank you :)

how to visualization t-sne?

Hello.
I would like to see the results visualized with T-SNE.
The current dataset is summer2winter.

I want to know how to use it in main.
Thank you.

Own Dataset

Hello, I am currently working on FONTS images style mixing and style transfer. If I use my own dataset for different 171 classes then I need to use output_k = 171 right? and also I wonder about the att_to_use what value I need to set for this? and what is the exact usage of this I am confused little bit about it. I just saw you are using this for validation. Can you little bit explain it more and when we use for specific n classes what it should be?

training on own dataset

how can we train in on custom domains??? when i try i am getting error
Traceback (most recent call last): File "main.py", line 524, in <module> main() File "main.py", line 201, in main main_worker(args.gpu, ngpus_per_node, args) File "main.py", line 257, in main_worker train_loader, val_loader, train_sampler = get_loader(args, {'train': train_dataset, 'val': val_dataset}) File "main.py", line 478, in get_loader pin_memory=True, sampler=train_sampler, drop_last=False) File "/home/mia/anish/experiments/tunit/tunitenv/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 213, in __init__ sampler = RandomSampler(dataset) File "/home/mia/anish/experiments/tunit/tunitenv/lib/python3.6/site-packages/torch/utils/data/sampler.py", line 94, in __init__ "value, but got num_samples={}".format(self.num_samples)) ValueError: num_samples should be a positive integer value, but got num_samples=0

FFHQ: IndexError list index out of range

Hey, I'm trying to get the tunit algorithm running with FFHQ (thumbnails) which are size 128x128. Just for context (although I don't think this is relevant) I had downloaded it from the Drive link (found here). The way that this code had been set up for FFHQ wasn't quite correct as it didn't take into account the folder structure so I modified the relvant sections everything from tot_targets on line 327 in datasetgetter.py to:

train_dataset = dataset
all = list(range(70000))
val_idx = random.sample(all, 7000)
train_idx = list(filter(lambda x: x not in val_idx, all))[:-24]  # make sure train_idx is evenly divisible by batch_size of 32

Now, when I go to train, the places errors get thrown are very confusingly not the same. Occasionally I will get a stack-trace pointing to for _, (data, _) in enumerate(train_loader): at line 142 (initialize_queue) in ops.py. More commonly though, I will get a stack-trace pointing to imgs, _ = next(train_it) at line 62 (trainGAN_UNSUP) in train_unsupervised.py:

Traceback (most recent call last):
  File "main.py", line 527, in <module>
    main()
  File "main.py", line 201, in main
    main_worker(args.gpu, ngpus_per_node, args)
  File "main.py", line 305, in main_worker
    trainFunc(train_loader, networks, opts, epoch, args, {'logger': logger, 'queue': queue})
  File "/data/nv419/machine_drive/tunit/train/train_unsupervised.py", line 62, in trainGAN_UNSUP
    imgs, _ = next(train_it)
  File "/data/nv419/anaconda3/envs/tunit/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 801, in __next__
    return self._process_data(data)
  File "/data/nv419/anaconda3/envs/tunit/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
    data.reraise()
  File "/data/nv419/anaconda3/envs/tunit/lib/python3.6/site-packages/torch/_utils.py", line 369, in reraise
    raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 1.
Original Traceback (most recent call last):
  File "/data/nv419/anaconda3/envs/tunit/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/data/nv419/anaconda3/envs/tunit/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/data/nv419/anaconda3/envs/tunit/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/data/nv419/anaconda3/envs/tunit/lib/python3.6/site-packages/torch/utils/data/dataset.py", line 256, in __getitem__
    return self.dataset[self.indices[idx]]
  File "/data/nv419/anaconda3/envs/tunit/lib/python3.6/site-packages/torchvision/datasets/folder.py", line 137, in __getitem__
    path, target = self.samples[index]
IndexError: list index out of range

Normally this error gets thrown at the 0th iteration. However, I've seen the tqdm bar (at times) move up to 4 iterations before having the error thrown 🤷‍♂️:
image

Been at this for hours now but the code isn't trivial to understand so I'm hoping one of the maintainers has some intuition behind this. Using Pytorch v1.2.0 on an Ubuntu machine. Error is there whether I'm using multiple GPUs or not

Add Google Colab

Love this implementation. For starters it might help some to try it out on Google Colab.

If I have time I try to implement it and open a pull request ;)

OOM of training summer2winter

Hi ,

I was trying to train summer2winter and utilize the command as below

python main.py --gpu 0 --dataset summer2winter --output_k 2 --data_path '../data/ob_1001id_paired_images' --p_semi 0 --img_size 128 --batch_size 32

I have encountered an issue relating to OOM and you can see the log as below.

Traceback (most recent call last):
  File "main.py", line 524, in <module>
    main()
  File "main.py", line 201, in main
    main_worker(args.gpu, ngpus_per_node, args)
  File "main.py", line 305, in main_worker
    trainFunc(train_loader, networks, opts, epoch, args, {'logger': logger, 'queue': queue})
  File "/workspace/tunit/train/train_unsupervised.py", line 135, in trainGAN_UNSUP
    d_gp = args.w_gp * compute_grad_gp(d_real_logit, x_ref, is_patch=False)
  File "/workspace/tunit/tools/ops.py", line 16, in compute_grad_gp
    create_graph=True, retain_graph=True, only_inputs=True)[0]
  File "/usr/local/lib/python3.6/dist-packages/torch/autograd/__init__.py", line 158, in grad
    inputs, allow_unused)
RuntimeError: CUDA out of memory. Tried to allocate 180.00 MiB

Any suggestion for this ?? Thanks

'fid_ema' referenced before assignment Error!

Hi. I'm so glad to see your model! But I have some issue.
I'm going to learn from custom data, But I met

Traceback (most recent call last):
File "main.py", line 524, in
main()
File "main.py", line 201, in main
main_worker(args.gpu, ngpus_per_node, args)
File "main.py", line 327, in main_worker
add_logs(args, logger, 'STATEMA/G_EMA{}/FID'.format(idx_fid), fid_ema[idx_fi d], epoch + 1)
UnboundLocalError: local variable 'fid_ema' referenced before assignment

this issue.
How can I Solve this Problem? Thanks!

Any TensorFlow implementation?

Hi.

This paper is simply great!

I was actually looking for a TensorFlow implementation, specifically TensorFlow-compatible checkpoints/frozengraphs/SavedModel. My plan is to convert it to a TensorFlow Lite model and create a demo mobile application it.

Looking forward to hearing from you.

I'm not sure why summer2winter CUDA out of memory.

Thank you for the awesome work.

I am now learning custom data in an unsupervised way. But there was a problem. The cuda out of memory occurs the moment you move to epoch 69->70.

'RuntimeError: CUDA out of memory. Tried to allocate 20.61 GiB (GPU 0; 23.65 GiB total capacity; 3.54 GiB already allocated; 17.74 GiB free; 1.55 GiB cached)'

The command I executed is:'python main.py --gpu 0 --dataset summer2winter --output_k 2 --data_path'../data' --p_semi 0.0 --img_size 256 --batch_size 1 --ddp'

Also, my gpu is TITAN RTX 1.

Thanks for letting me know about this issue.

Seek the AnimalFaces Dataset

Hello!
I'm interested in the experiment of AnimalFaces Dataset, but I didn't find a pure AnimalFaces in public work like FUNIT, the cost of dowmloading the original ImageNet is too large for me, so I wander if you have uploaded the AnimalFaces Dataset (not afhq) to some online network location? I believe it will be very helpful if they have already been uploaded.
Best!

About custom dataset

It seems that the following code needs to be modified.

''' validation.py
#val_dataset = data_loader['TRAINSET'] if args.dataset in ['animal_faces', 'lsun_car', 'ffhq'] else data_loader['VALSET']
val_dataset = data_loader['TRAINSET'] if args.dataset in ['u own dataset', 'animal_faces', 'lsun_car', 'ffhq'] else data_loader['VALSET']
'''

Otherwise you will get the following error:

‘’‘
AttributeError: ‘Subset’ object has no attribute ‘targets’
’‘’

Why the style encoder maps all the images to the same style code?

Hello. Could you please give some explanation and advise for the scenario explained below.

I am not using TUNIT but a very similar architecture where I have a GAN jointly trained with a style encoder. The style encoder is trained as a classifier in a supervised setting and its middle layer features are injected as a style code in the generator. During training the validation results are pretty good (which I assume is down to the L1 loss I am using because of the paired supervision).
During inference the style encoder maps all images to a same style code.

The exact same scenario is mentioned in section 3.3. of your paper where you define the style contrastive loss for the generator. Quoting from your paper "This loss guides the generated image G(x, ˜s) to have a style similar to the reference
image x˜ and dissimilar to negative (other) samples. By doing so, we avoid the degenerated solution where the encoder
maps all the images to the same style code of the reconstruction loss [5] based on L1 or L2 norm." Where reference [5] is the starGAN-v2.

In my case I am also using a style classification loss on the style image for the generator however it seems to completely ignore it during inference.

Could you please explain

  1. Why your referred to StarGAN-v2 for this particular scenario?
  2. Can you give an advise so that my style encoder doesn't ignore the style code at inference?

Training on non-square images

Hi,

is it possible to train on images with a different vertical and horizontal resolution?

Is it possible to train on images which are not the power of 2?

Thanks, Fabian

Training on smaller GPU

Hi @FriedRonaldo ,

First of all, thank you for the awesome work.

My question is, do you have any pointers for training on a GPU with less RAM? Like my 2070 8GB?

For example, I keep getting CUDA out of memory messages when training with two classes/labels. Even when decreasing batch_size and val_batch significantly.

Many thanks in advance.

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.