hardikbansal / cyclegan Goto Github PK
View Code? Open in Web Editor NEWTensorflow implementation of CycleGAN
Tensorflow implementation of CycleGAN
I think there are some problems in your function input_read() in main.py.
Shouldn't we add code such like "while not coord.should_stop():" to make that the variable image_file_A always get images from variable filename_queue_A ?
Anyway ,when I run you code, there are some problems. I am confused how you can get your results.
Hope for your help, thank you
In the original paper, the discriminator used patchGAN.
In your model.py, it seems to be implemented. (random_crop, I do not know if this is correct)
Why did not you use this?
fake_pool[random_id] = fake --- what does use for in dis code? coz it return temp
def fake_image_pool(self, num_fakes, fake, fake_pool):
''' dis function saves teh generated image to corresponding pool of images.
In starting. It keeps on feeling teh pool till it is full and tan randomly selects an
already stored image and replace it with new one.'''
if(num_fakes < pool_size):
fake_pool[num_fakes] = fake
return fake
else :
p = random.random()
if p > 0.5:
random_id = random.randint(0,pool_size-1)
temp = fake_pool[random_id]
fake_pool[random_id] = fake
return temp
else :
return fake
From my opinion, paired model pix2pix is special case of unpaired model cyclegan, so i try to use labeled fake pic and real camera pic as input A AND B to train incyclegan model. both size of them are 96wx32h(not square w==h), then i find main.py cannot run and report reshape error(you can use no-square pic and train model then maybe get the error).after some guess and detail look on your codes, it seems input_A's width set to height of the A_input. But it can also run if train data and test data are both square. anyhow, after adjusted(swtich) position of w and h, i run the model trained and tested, also the final result is not as better as i image, maybe i need adjust lr or other Hparams.
thanks so much for provide tensorflow version of cyclegan.
finally, sorry for my poor English.
Hello,
I am using your tensorflow implementation of the Cycle GAN for my own dataset.
However, there are few questions I want to ask about, and I hope you can be able to help me:
1- Before training, I create the csv file, which is pairing all images in both domains together randomly, but my question is, between every epoch and the other, do the batches get shuffled ? or for each epoch they are provided by the same sequence ?
2- I don't understand what is the "CycA" and "CycB" output images
3- If I don't want to use your network bidirectionally, is there something which I have/need to do ? I mean, I only want to translate from domain A -> B, and not vice versa
4- My dataset are images which are much higher in resolution than the provided dataset. They are 1242x375, will this be applicable for the deploying of the network ? or what shall I edit exactly in any part of the code to adapt my dataset
Thanks a lot in advance
Looking forward to hearing from you soon
Best Regards,
Mostafa
I'm using TensorFlow of version 1.10.0. I need to do the following change in file main.py
to run this code:
size()
into size
on line 99 & 104;tf.local_variables_initializer()
after line 247&330 and add sess.run()
after line 251&334.Add I created a pull request for this. I also made some changes on the code style.
I should've sent a PR but anyway - I get the following error when I try and run the code
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value matching_filenames [[Node: matching_filenames/read = Identity[T=DT_STRING, _class=["loc:@matching_filenames"], _device="/job:localhost/replica:0/task:0/cpu:0"](matching_filenames)]]
This is resolved by
init = (tf.global_variables_initializer(), tf.local_variables_initializer())
as mentioned here
Hello, i am having tensorflow version 1.11.0
i had issue on initialize varaible but solved that issue by modifing to this (tf.global_variables_initializer(), tf.local_variables_initializer()), earlier it had only global initializer.
After that i am having another issue on this line
if(image_tensor.size() == img_sizebatch_sizeimg_layer):
it seems to be issue of size() func but displaying error of "int object is not callable"
i am running in python 3. and have horse2zebra images.
As the title
can you give me a suggestion
hello hardikbansal
I am fuzzy on build_gen_discriminator and patch_discriminator. Can you tell me the difference between build_gen_discriminato and patch_discriminator ?
def build_gen_discriminator(inputdisc, name="discriminator"):
with tf.variable_scope(name):
f = 4
o_c1 = general_conv2d(inputdisc, ndf, f, f, 2, 2, 0.02, "SAME", "c1", do_norm=False, relufactor=0.2)
o_c2 = general_conv2d(o_c1, ndf*2, f, f, 2, 2, 0.02, "SAME", "c2", relufactor=0.2)
o_c3 = general_conv2d(o_c2, ndf*4, f, f, 2, 2, 0.02, "SAME", "c3", relufactor=0.2)
o_c4 = general_conv2d(o_c3, ndf*8, f, f, 1, 1, 0.02, "SAME", "c4",relufactor=0.2)
o_c5 = general_conv2d(o_c4, 1, f, f, 1, 1, 0.02, "SAME", "c5",do_norm=False,do_relu=False)
return o_c5
def patch_discriminator(inputdisc, name="discriminator"):
with tf.variable_scope(name):
f= 4
patch_input = tf.random_crop(inputdisc,[1,70,70,3])
o_c1 = general_conv2d(patch_input, ndf, f, f, 2, 2, 0.02, "SAME", "c1", do_norm="False", relufactor=0.2)
o_c2 = general_conv2d(o_c1, ndf*2, f, f, 2, 2, 0.02, "SAME", "c2", relufactor=0.2)
o_c3 = general_conv2d(o_c2, ndf*4, f, f, 2, 2, 0.02, "SAME", "c3", relufactor=0.2)
o_c4 = general_conv2d(o_c3, ndf*8, f, f, 2, 2, 0.02, "SAME", "c4", relufactor=0.2)
o_c5 = general_conv2d(o_c4, 1, f, f, 1, 1, 0.02, "SAME", "c5",do_norm=False,do_relu=False)
return o_c5
thank you vey much
This is a test issue and has to be ignored.
While in source code main.py, below line can't procedure gray picture(8 bit color deep) in horse2zebra dataset(after unzip horse2zebra dataset, I find some picture is gray with 8 bit deep in trainB), and get err.
self.B_input[i] = image_tensor.reshape((batch_size,img_height, img_width, img_layer))
ValueError: cannot reshape array of size 65536 into shape (1,256,256,3)
Hi!
I am pretty sure that I am making a stupid mistake but when I try to run the code on the horse2zebra dataset I get the a FailedPreconditionError, details see below. The dataset is in the correct form in the cycleGan folder ./input/horse2zebra/trainA etc. I have a Windows machine with the recent version of tensorflow installed (I tried both pyton 3.5 and 3.6). I want to try how this cycle Gan implementation worksfor my research, so help would be much appreciated!
Thx!
Here is the full error message:
Traceback (most recent call last):
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1139, in _do_call
return fn(*args)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1121, in _run_fn
status, run_metadata)
File "C:\Users\Eulsen\Anaconda3\lib\contextlib.py", line 88, in exit
next(self.gen)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value matching_filenames
[[Node: matching_filenames/read = IdentityT=DT_STRING, _class=["loc:@matching_filenames"], _device="/job:localhost/replica:0/task:0/cpu:0"]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 362, in
main()
File "main.py", line 356, in main
model.train()
File "main.py", line 254, in train
self.input_read(sess)
File "main.py", line 87, in input_read
num_files_A = sess.run(self.queue_length_A)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 789, in run
run_metadata_ptr)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 997, in _run
feed_dict_string, options, run_metadata)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1132, in _do_run
target_list, options, run_metadata)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1152, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value matching_filenames
[[Node: matching_filenames/read = IdentityT=DT_STRING, _class=["loc:@matching_filenames"], _device="/job:localhost/replica:0/task:0/cpu:0"]]
Caused by op 'matching_filenames/read', defined at:
File "main.py", line 362, in
main()
File "main.py", line 356, in main
model.train()
File "main.py", line 238, in train
self.input_setup()
File "main.py", line 56, in input_setup
filenames_A = tf.train.match_filenames_once("./input/horse2zebra/trainA/*.jpg")
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\training\input.py", line 69, in match_filenames_once
collections=[ops.GraphKeys.LOCAL_VARIABLES])
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1679, in variable
caching_device=caching_device, name=name, dtype=dtype)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\ops\variables.py", line 200, in init
expected_shape=expected_shape)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\ops\variables.py", line 319, in _init_from_args
self._snapshot = array_ops.identity(self._variable, name="read")
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 1303, in identity
result = _op_def_lib.apply_op("Identity", input=input, name=name)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op
op_def=op_def)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 2506, in create_op
original_op=self._default_original_op, op_def=op_def)
File "C:\Users\Eulsen\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1269, in init
self._traceback = _extract_stack()
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value matching_filenames
[[Node: matching_filenames/read = IdentityT=DT_STRING, _class=["loc:@matching_filenames"], _device="/job:localhost/replica:0/task:0/cpu:0"]]
Hello,
I don't see any use of the files under testA or testB in your code, are you testing the model on training data?
thanks!
I'm confused about a question, Does the size of pool_size matter? If I set it bigger, will it learn better?
I appreciate your sharing highly !
Have you tested the results and compared with the original version ?
Hi, @hardikbansal @debin168 I'm using tf 1.4 and met problem below.
In input_read, the tensor.size() can't be recognized Thank you!
i tried running the code, after couple of epochs, save_training_images is dumping empty image. It doesn't look relisting. is it because yet to learn or something wrong in code?
I’m puzzled since your already use a 70X70 patch discriminator in gen_discriminator but you still use random crop to build another “patch discriminator ”. I guess 70X70 is the size of the receptive field instead of the size of a random crop.
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.