Git Product home page Git Product logo

stargan-v2-tensorflow's Introduction

StarGAN v2 — Official TensorFlow Implementation [Paper] [Pytorch]

Implemented by Junho Kim

Requirements

  • Tensorflow == 2.1.0
  • Tensorflow-addons == 0.9.1
  • opencv-python
  • Pillow
  • tqdm

Usage

├── dataset
   └── YOUR_DATASET_NAME
       ├── train
           ├── domain1 (domain folder)
               ├── xxx.jpg (domain1 image)
               ├── yyy.png
               ├── ...
           ├── domain2
               ├── aaa.jpg (domain2 image)
               ├── bbb.png
               ├── ...
           ├── ...
           
       ├── test
           ├── ref_imgs (domain folder)
               ├── domain1 (domain folder)
                   ├── ttt.jpg (domain1 image)
                   ├── aaa.png
                   ├── ...
               ├── domain2
                   ├── kkk.jpg (domain2 image)
                   ├── iii.png
                   ├── ...
               ├── ...
               
           ├── src_imgs
               ├── src1.jpg 
               ├── src2.png
               ├── ...

Train

python main.py --dataset celebA-HQ_gender --phase train

Test

python main.py --dataset celebA-HQ_gender --phase test

Tensorflow results (100K)

Latent-guided synthesis

CelebA-HQ

AFHQ

Reference-guided synthesis

CelebA-HQ

AFHQ

License

The source code, pre-trained models, and dataset are available under 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.

For business inquiries, please contact [email protected].
For technical and other inquires, please contact [email protected].
For questions about the tensorflow implementation, please contact [email protected].

Citation

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

@inproceedings{choi2020starganv2,
  title={StarGAN v2: Diverse Image Synthesis for Multiple Domains},
  author={Yunjey Choi and Youngjung Uh and Jaejun Yoo and Jung-Woo Ha},
  booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
  year={2020}
}

stargan-v2-tensorflow's People

Contributors

clovaaiadmin avatar taki0112 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

stargan-v2-tensorflow's Issues

Single Image Transition vs Multiple Image Transistion

Not an issue. But just a question.

This might be a beginner level question. I will give a scenario. Like say we have cat, dog and tiger image. And say we are transitioning from cat to dog.

Will the quality of cat to dog transition will be better if we only train with cat and dog images (like cyclegan)?

Or we train with all cat,dog and tiger images?

Like cat as source image. Dog and Tiger as Target Images. Transitioning from cat to dog. And cat to tiger.

Will the quality and accuracy be same when we do multiple transitioning and single transitioning?

Pre-trained models

Hi, can you share the pre-trained models of the networks trained using this code? Also, what were the FID and LPIPS score comparison between TensorFlow and PyTorch code?

Training style encoder

Shouldn't we update style encoder when we call g_train_step() with x_ref and not with z_trg?

 if z_trgs is not None:
      f_train_variable = self.mapping_network.trainable_variables
      e_train_variable = self.style_encoder.trainable_variables

      f_gradient = g_tape.gradient(g_loss, f_train_variable)
      e_gradient = g_tape.gradient(g_loss, e_train_variable)

      self.f_optimizer.apply_gradients(zip(f_gradient, f_train_variable))
      self.e_optimizer.apply_gradients(zip(e_gradient, e_train_variable))

Should be:

 if z_trgs is not None:
      f_train_variable = self.mapping_network.trainable_variables
      f_gradient = g_tape.gradient(g_loss, f_train_variable)
      self.f_optimizer.apply_gradients(zip(f_gradient, f_train_variable))
 else:
      e_train_variable = self.style_encoder.trainable_variables
      e_gradient = g_tape.gradient(g_loss, e_train_variable)
      self.e_optimizer.apply_gradients(zip(e_gradient, e_train_variable))

loading dataset

hi,
Can you describe the directory structure of your data set? and how to split source and reference image?
I trained with my own data set and the results are strange

ValueError

I am getting this error in Colab

`

Traceback (most recent call last):
File "main.py", line 117, in
main()
File "main.py", line 103, in main
gan.build_model()
File "/content/stargan-v2-tensorflow/StarGAN_v2.py", line 197, in build_model
self.mapping_network_ema = MappingNetwork(self.style_dim, self.hidden_dim, self.num_domains, sn=False, name='MappingNetwork')
File "/content/stargan-v2-tensorflow/networks.py", line 85, in init
self.shared_layers, self.unshared_layers = self.architecture_init()
File "/content/stargan-v2-tensorflow/networks.py", line 96, in architecture_init
shared_layers = Sequential(layers)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/base.py", line 457, in _method_wrapper
result = method(self, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/sequential.py", line 142, in init
self.add(layer)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/base.py", line 457, in _method_wrapper
result = method(self, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/sequential.py", line 189, in add
'to pass a unique name.' % (layer.name,))
ValueError: All layers added to a Sequential model should have unique names. Name "relu" is already the name of a layer in this model. Update the name argument to pass a unique name `

ValueError: All layers added to a Sequential model should have unique names.

Please help. I used tensorflow 2.10.1
Traceback (most recent call last):
File "D:\stargan-v2-tensorflow\main.py", line 117, in
main()
File "D:\stargan-v2-tensorflow\main.py", line 103, in main
gan.build_model()
File "D:\stargan-v2-tensorflow\StarGAN_v2.py", line 146, in build_model
self.style_encoder = StyleEncoder(self.img_size, self.style_dim, self.num_domains, max_conv_dim=self.hidden_dim, sn=False, name='StyleEncoder')
File "D:\stargan-v2-tensorflow\networks.py", line 141, in init
self.shared_layers, self.unshared_layers = self.architecture_init()
File "D:\stargan-v2-tensorflow\networks.py", line 161, in architecture_init
shared_layers = Sequential(blocks)
File "C:\Users\user\anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\python\trackable\base.py", line 205, in _method_wrapper
result = method(self, *args, **kwargs)
File "C:\Users\user\anaconda3\envs\tf-gpu\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\user\anaconda3\envs\tf-gpu\lib\site-packages\keras\engine\sequential.py", line 190, in add
raise ValueError(
ValueError: All layers added to a Sequential model should have unique names. Name "leaky_relu" is already the name of a layer in this model. Update the name argument to
pass a unique name.

Buffer Size Error

Hello together!

When trying to train (only using the Files that were provided, no own data (yet)).
I encounter the following error:
tensorflow.python.framework.errors_impl.InvalidArgumentError: buffer_size must be greater than zero. [Op:ShuffleDatasetV2]

Full Error Stack:
Traceback (most recent call last):
File "main.py", line 117, in
main()
File "main.py", line 103, in main
gan.build_model()
File "C:\Users\TOGERLA\Desktop\stargan-v2-tensorflow-master\StarGAN_v2.py", line 138, in build_model
img_and_domain = img_and_domain.shuffle(buffer_size=dataset_num, reshuffle_each_iteration=True).repeat()
File "C:\Users\TOGERLA\Desktop\stargan-v2-tensorflow-master\venv\lib\site-packages\tensorflow_core\python\data\ops\dataset_ops.py", line 1193, in shuffle
return ShuffleDataset(self, buffer_size, seed, reshuffle_each_iteration)
File "C:\Users\TOGERLA\Desktop\stargan-v2-tensorflow-master\venv\lib\site-packages\tensorflow_core\python\data\ops\dataset_ops.py", line 3535, in init
**self._flat_structure)
File "C:\Users\TOGERLA\Desktop\stargan-v2-tensorflow-master\venv\lib\site-packages\tensorflow_core\python\ops\gen_dataset_ops.py", line 5221, in shuffle_dataset_v2
_ops.raise_from_not_ok_status(e, name)
File "C:\Users\TOGERLA\Desktop\stargan-v2-tensorflow-master\venv\lib\site-packages\tensorflow_core\python\framework\ops.py", line 6606, in raise_from_not_ok_status
six.raise_from(core._status_to_exception(e.code, message), None)
File "", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: buffer_size must be greater than zero. [Op:ShuffleDatasetV2]

I might be able to fix the issue myself, but I'll still try to document it here for other people to reproduce :)

Have a nice Christmas!
Tobias

How to use multiple gpu

    def build_model(self):
        if self.phase == 'train':
            """ Input Image"""
            img_class = Image_data(self.img_size, self.img_ch, self.dataset_path, self.domain_list, self.augment_flag)
            img_class.preprocess()

            dataset_num = len(img_class.images)
            print("Dataset number : ", dataset_num)

            img_and_domain = tf.data.Dataset.from_tensor_slices((img_class.images, img_class.shuffle_images, img_class.domains))

            gpu_device = '/gpu:1'

            img_and_domain = img_and_domain.shuffle(buffer_size=dataset_num, reshuffle_each_iteration=True).repeat()
            img_and_domain = img_and_domain.map(map_func=img_class.image_processing, num_parallel_calls=AUTOTUNE).batch(self.batch_size, drop_remainder=True)
            img_and_domain = img_and_domain.apply(prefetch_to_device(gpu_device, buffer_size=AUTOTUNE))

How to set up multiple gpu?

Tensorflow 2.1.0 is unavailable on PyPi

When I try to install tensorflow with pip install Tensorflow==2.1.0 I'm getting an error No matching distribution found for Tensorflow==2.1.0. Only offered versions are 2.2.0 and higher.
Should the code be working with those?

Generator and Discriminator loss NAN after 613 epochs

I am trying to train starGan on Alderley Day/Night Dataset to turn day images to night, but after 613 epoch the loss turns NAN, GAN type is gan-gp and every thing is set to default, can you help to elaborate what could be the cause of this divergence

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.