adversarial_retinal_synthesis icon indicating copy to clipboard operation
adversarial_retinal_synthesis copied to clipboard

can you help me to solve this error,thank you!!!!

Open jiahaoMeng opened this issue 8 years ago • 14 comments

runfile('/media/meng/C disk/mjh/gan/end to end /code/adversarial_retinal_synthesis-master/train.py', wdir='/media/meng/C disk/mjh/gan/end to end /code/adversarial_retinal_synthesis-master') Reloaded modules: models, util, util.data, util.util Traceback (most recent call last):

File "", line 1, in runfile('/media/meng/C disk/mjh/gan/end to end /code/adversarial_retinal_synthesis-master/train.py', wdir='/media/meng/C disk/mjh/gan/end to end /code/adversarial_retinal_synthesis-master')

File "/home/meng/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 710, in runfile execfile(filename, namespace)

File "/home/meng/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 101, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "/media/meng/C disk/mjh/gan/end to end /code/adversarial_retinal_synthesis-master/train.py", line 422, in is_binary=params.is_a_binary)

File "/media/meng/C disk/mjh/gan/end to end /code/adversarial_retinal_synthesis-master/models.py", line 235, in g_vae z = Lambda(sampling, output_shape=(latent_dim,))([z_mean, z_log_var])

File "/home/meng/anaconda3/lib/python3.6/site-packages/Keras-1.2.2-py3.6.egg/keras/engine/topology.py", line 572, in call self.add_inbound_node(inbound_layers, node_indices, tensor_indices)

File "/home/meng/anaconda3/lib/python3.6/site-packages/Keras-1.2.2-py3.6.egg/keras/engine/topology.py", line 635, in add_inbound_node Node.create_node(self, inbound_layers, node_indices, tensor_indices)

File "/home/meng/anaconda3/lib/python3.6/site-packages/Keras-1.2.2-py3.6.egg/keras/engine/topology.py", line 172, in create_node output_tensors = to_list(outbound_layer.call(input_tensors, mask=input_masks))

File "/home/meng/anaconda3/lib/python3.6/site-packages/Keras-1.2.2-py3.6.egg/keras/layers/core.py", line 641, in call return self.function(x, **arguments)

File "/media/meng/C disk/mjh/gan/end to end /code/adversarial_retinal_synthesis-master/models.py", line 232, in sampling mean=0., std=1.)

File "/home/meng/anaconda3/lib/python3.6/site-packages/Keras-1.2.2-py3.6.egg/keras/backend/tensorflow_backend.py", line 2935, in random_normal dtype=dtype, seed=seed)

File "/home/meng/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/random_ops.py", line 71, in random_normal shape_tensor = _ShapeTensor(shape)

File "/home/meng/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/random_ops.py", line 42, in _ShapeTensor return ops.convert_to_tensor(shape, dtype=dtype, name="shape")

File "/home/meng/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 836, in convert_to_tensor as_ref=False)

File "/home/meng/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 926, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)

File "/home/meng/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 229, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name)

File "/home/meng/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 208, in constant value, dtype=dtype, shape=shape, verify_shape=verify_shape))

File "/home/meng/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 472, in make_tensor_proto "supported type." % (type(values), values))

TypeError: Failed to convert object of type <class 'tuple'> to Tensor. Contents: (Dimension(None), 16). Consider casting elements to a supported type.

jiahaoMeng avatar Mar 05 '18 14:03 jiahaoMeng

It's hard to say what is the problem. Are you sure you are using the th dim ordering?

costapt avatar Mar 05 '18 23:03 costapt

I've added this sentence. from keras import backend as K K.set_image_dim_ordering('th') , when I run train.py.
ipdb> vae = m.g_vae(params.a_ch, params.a_ch, params.nfatoa, params.latent_dim, is_binary=params.is_a_binary) *** TypeError: Failed to convert object of type <class 'tuple'> to Tensor. Contents: (Dimension(None), 16). Consider casting elements to a supported type.

jiahaoMeng avatar Mar 06 '18 01:03 jiahaoMeng

Hi,

After adding the sentence K.set_image_dim_ordering('th'), I solved that error by changing line 231 in the models.py file. This way,

batch_size = K.shape(z_mean)[0] epsilon = K.random_normal(shape=(batch_size, latent_dim), mean=0., std=1.)

However, I am getting another error, not sure why.

**Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 754, in run self.__target(*self.__args, **self.__kwargs) File "/home/cvblab03/Documents/GANexperiment/vess2ret/vess2retEnv/local/lib/python2.7/site-packages/keras/engine/training.py", line 429, in data_generator_task generator_output = next(self._generator) File "train.py", line 75, in discriminator_generator b_fake = g.predict(a_fake) File "/home/cvblab03/Documents/GANexperiment/vess2ret/vess2retEnv/local/lib/python2.7/site-packages/keras/engine/training.py", line 1269, in predict self._make_predict_function() File "/home/cvblab03/Documents/GANexperiment/vess2ret/vess2retEnv/local/lib/python2.7/site-packages/keras/engine/training.py", line 798, in _make_predict_function **kwargs) File "/home/cvblab03/Documents/GANexperiment/vess2ret/vess2retEnv/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 1961, in function return Function(inputs, outputs, updates=updates) File "/home/cvblab03/Documents/GANexperiment/vess2ret/vess2retEnv/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 1919, in init with tf.control_dependencies(self.outputs): File "/home/cvblab03/Documents/GANexperiment/vess2ret/vess2retEnv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 5027, in control_dependencies return get_default_graph().control_dependencies(control_inputs) File "/home/cvblab03/Documents/GANexperiment/vess2ret/vess2retEnv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 4631, in control_dependencies c = self.as_graph_element(c) File "/home/cvblab03/Documents/GANexperiment/vess2ret/vess2retEnv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3590, in as_graph_element return self._as_graph_element_locked(obj, allow_tensor, allow_operation) File "/home/cvblab03/Documents/GANexperiment/vess2ret/vess2retEnv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3669, in _as_graph_element_locked raise ValueError("Tensor %s is not an element of this graph." % obj) ValueError: Tensor Tensor("Tanh_2:0", shape=(?, 3, 256, 256), dtype=float32) is not an element of this graph.

Exception KeyError: KeyError(<weakref at 0x7f3ff4fa7f70; to 'tqdm' at 0x7f3ff4d53710>,) in <bound method tqdm.del of 0%| | 0/100 [00:00<?, ?it/s]> ignored Traceback (most recent call last): File "train.py", line 456, in HERE WE ALRIGHT POSSIBLE ERROR. BEFORE train(models, it_train, it_val, params) File "train.py", line 338, in train train_iteration(models, generators, losses, params) File "train.py", line 269, in train_iteration dhist = train_discriminator(d, d_gen, batch_size=params.batch_size) File "train.py", line 101, in train_discriminator return d.fit_generator(it, samples_per_epoch=batch_size*2, nb_epoch=1, verbose=False) File "/home/cvblab03/Documents/GANexperiment/vess2ret/vess2retEnv/local/lib/python2.7/site-packages/keras/engine/training.py", line 1532, in fit_generator str(generator_output)) ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None**

I think is something related to the g_unet architecture. But I am not sure :(

diazandr3s avatar May 21 '18 20:05 diazandr3s

I proposed a solution for these issues. Please check the Pull request @costapt @jiahaoMeng

diazandr3s avatar May 29 '18 12:05 diazandr3s

@diazandr3s
Thank you very much for your help, but when I did exactly what you did, I encountered such a mistake and I hope to get your help, thanks again. runfile('/media/meng/My Passport/adversarial_retinal_synthesis-master/train.py', wdir='/media/meng/My Passport/adversarial_retinal_synthesis-master') Reloaded modules: util.util, util, models, util.data 0%| | 0/100 [00:00<?, ?it/s]Exception in thread Thread-15: Traceback (most recent call last): File "/home/meng/.conda/envs/python27/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/home/meng/.conda/envs/python27/lib/python2.7/threading.py", line 754, in run self.__target(*self.__args, **self.__kwargs) File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/Keras-1.2.2-py2.7.egg/keras/engine/training.py", line 429, in data_generator_task generator_output = next(self._generator) File "/media/meng/My Passport/adversarial_retinal_synthesis-master/train.py", line 113, in code_discriminator_generator z_fake = encoder.predict(a) File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/Keras-1.2.2-py2.7.egg/keras/engine/training.py", line 1269, in predict self._make_predict_function() File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/Keras-1.2.2-py2.7.egg/keras/engine/training.py", line 798, in _make_predict_function **kwargs) File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/Keras-1.2.2-py2.7.egg/keras/backend/tensorflow_backend.py", line 1961, in function return Function(inputs, outputs, updates=updates) File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/Keras-1.2.2-py2.7.egg/keras/backend/tensorflow_backend.py", line 1919, in init with tf.control_dependencies(self.outputs): File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 4604, in control_dependencies return get_default_graph().control_dependencies(control_inputs) File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 4310, in control_dependencies c = self.as_graph_element(c) File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3323, in as_graph_element return self._as_graph_element_locked(obj, allow_tensor, allow_operation) File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3402, in _as_graph_element_locked raise ValueError("Tensor %s is not an element of this graph." % obj) ValueError: Tensor Tensor("add_1153:0", shape=(?, 16), dtype=float32) is not an element of this graph.

Traceback (most recent call last):

File "", line 1, in runfile('/media/meng/My Passport/adversarial_retinal_synthesis-master/train.py', wdir='/media/meng/My Passport/adversarial_retinal_synthesis-master')

File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile execfile(filename, namespace)

File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile builtins.execfile(filename, *where)

File "/media/meng/My Passport/adversarial_retinal_synthesis-master/train.py", line 474, in train(models, it_train, it_val, params)

File "/media/meng/My Passport/adversarial_retinal_synthesis-master/train.py", line 351, in train train_iteration(models, generators, losses, params)

File "/media/meng/My Passport/adversarial_retinal_synthesis-master/train.py", line 283, in train_iteration cdhist = train_discriminator(code_d, code_d_gen, samples_per_batch=params.batch_size)

File "/media/meng/My Passport/adversarial_retinal_synthesis-master/train.py", line 106, in train_discriminator return d.fit_generator(it, samples_per_epoch=samples_per_batch*2, nb_epoch=1, verbose=False)

File "/home/meng/.conda/envs/python27/lib/python2.7/site-packages/Keras-1.2.2-py2.7.egg/keras/engine/training.py", line 1532, in fit_generator str(generator_output))

ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None

jiahaoMeng avatar Jun 04 '18 08:06 jiahaoMeng

@jiahaoMeng
You are right, I got the same error before. I forgot to add the complete solution. Please check the newly added piece of code. Let me know if it works.

diazandr3s avatar Jun 04 '18 11:06 diazandr3s

@diazandr3s Thank you again for your help!When I modified it according to the changes you made, I encountered the first question again. So I modified the following sentence, the code can run. if K.backend == 'tensorflow': batch_size = K.shape(z_mean)[0] else: batch_size = z_mean.shape[0] replaced: batch_size = K.shape(z_mean)[0]

jiahaoMeng avatar Jun 05 '18 02:06 jiahaoMeng

@diazandr3s Have you ever run the test code? I encountered this problem when I run the test code. Traceback (most recent call last): File "test1.py", line 216, in save_generated_images(sampler, params.N, params) File "test1.py", line 113, in save_generated_images expt_dir = join_and_create_dir(params.results_dir, params.expt_name) File "test1.py", line 33, in join_and_create_dir path = os.path.join(*paths) File "/usr/lib/python2.7/posixpath.py", line 68, in join if b.startswith('/'): AttributeError: 'NoneType' object has no attribute 'startswith'

And the pictures I trained are not very good. I don't know what the problem is. results

jiahaoMeng avatar Jun 05 '18 02:06 jiahaoMeng

Hi @jiahaoMeng

Regarding the image quality, @costapt could tell us more. You can modify the code to see the vessel masks as binary images and not as grey-scale.

diazandr3s avatar Jun 05 '18 16:06 diazandr3s

Thank you for your help @diazandr3s !

I am not sure what might be the issue with the test script. By reading the error message it seems like params.results_dir and/or params.expt_name might be incorrectly set. Can you confirm their values?

About the results quality, it usually takes a long time to fully train the model, it may be the case that it still did not converge. Can you send the train and val losses?

costapt avatar Jun 06 '18 08:06 costapt

@costapt Thank you for your help! code_d_loss code_d_val_loss d_loss d_val_loss p2p2p_loss p2p2p_val_loss p2p_loss p2p_val_loss

jiahaoMeng avatar Jun 10 '18 07:06 jiahaoMeng

It looks like the model still needs more training, you can see that the Pix2Pix loss was starting to decrease.

I remember that I have seen images like those during training, so I believe that the images will get sharper with more time.

costapt avatar Jun 21 '18 09:06 costapt

@jiahaoMeng I recently reproduced the code of this paper and found that the problems I encountered were the same as yours。How does the code of your experiment work in the end? Did you modify the code?Thank you very much for your reply. image

FFjiahao avatar Mar 16 '22 07:03 FFjiahao