clovaai / stargan-v2-tensorflow Goto Github PK
View Code? Open in Web Editor NEWStarGAN v2 - Official Tensorflow Implementation (CVPR 2020)
License: Other
StarGAN v2 - Official Tensorflow Implementation (CVPR 2020)
License: Other
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?
Can not run batch_size = 2 with 256x256 on 10G NVIDIA GPU card ??!?
This model is a bit too much for NVIDIA. Any hint gents ?
Steve
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.
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?
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?
from where I can get main.py file ?
Can someone help if there are changes in the hyper parameters if I want to change image size (output) to 512x512 or even 1024x1024, please?
Thanks,
Steve
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 `
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))
This is not an issue but I am curious why there is such a big difference. Is it about implementation or difference btw Tensorflow vs Pytorch? thanks
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
stargan-v2-tensorflow/StarGAN_v2.py
Line 144 in 1297463
Seems missing self.img_ch as the second argument
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
Hi,
According to the official TF documentation, ds_weight decay implemented on this way will not affect the loss weight inside g_train function. Please, take a look here: https://www.tensorflow.org/guide/function#depending_on_python_global_and_free_variables
Have you observed that behavior in your experiments as well?
Maybe loss weights can be passed as an argument to this function or directly converted to tf.Variable ?
Thank you for your excellent works! Could you please to release your pretrained models, I'll be very appreciated about that.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.