https://gist.github.com/Wermarter/466e9585579ef65927fa934fe4e0ffd4 Here I'm trying to implement Variational AutoEncoder in Tensorflow with TFLearn.
I build the computations for training, encoding, generating in one big graph in self.training_model.session
. The self.generating_model
and self.recognition_model
share the same session as self.training_model
.
Everything went fine when I ran the generating_model
to generate MNIST 2D Latent space. But error appeared when I ran self.recognition_model
to encode the given input_data, it required me to given input value to the self.train_data
which belongs to the self.training_model
.
Here's the full error:
Traceback (most recent call last):
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1039, in _do_call
return fn(*args)
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1021, in _run_fn
status, run_metadata)
File "/home/wermarter/anaconda3/lib/python3.5/contextlib.py", line 66, in __exit__
next(self.gen)
File "/home/wermarter/anaconda3/lib/python3.5/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.InvalidArgumentError: You must feed a value for placeholder tensor 'train_data/X' with dtype float
[[Node: train_data/X = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
[[Node: add_5/_47 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_8_add_5", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/wermarter/Desktop/vae.py", line 178, in <module>
main()
File "/home/wermarter/Desktop/vae.py", line 172, in main
vae.img_transition(trainX[4], trainX[100])
File "/home/wermarter/Desktop/vae.py", line 130, in img_transition
enc_A = self.encode(A)[0]
File "/home/wermarter/Desktop/vae.py", line 121, in encode
return self.recognition_model.predict({self.input_data: input_data})
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tflearn/models/dnn.py", line 257, in predict
return self.predictor.predict(feed_dict)
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tflearn/helpers/evaluator.py", line 69, in predict
return self.session.run(self.tensors[0], feed_dict=feed_dict)
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 778, in run
run_metadata_ptr)
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 982, in _run
feed_dict_string, options, run_metadata)
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1032, in _do_run
target_list, options, run_metadata)
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1052, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'train_data/X' with dtype float
[[Node: train_data/X = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
[[Node: add_5/_47 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_8_add_5", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'train_data/X', defined at:
File "/home/wermarter/Desktop/vae.py", line 178, in <module>
main()
File "/home/wermarter/Desktop/vae.py", line 169, in main
vae = VAE()
File "/home/wermarter/Desktop/vae.py", line 28, in __init__
self._build_training_model()
File "/home/wermarter/Desktop/vae.py", line 78, in _build_training_model
self.train_data = tflearn.input_data(shape=[None, *self.img_shape], name='train_data')
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tflearn/layers/core.py", line 81, in input_data
placeholder = tf.placeholder(shape=shape, dtype=dtype, name="X")
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py", line 1507, in placeholder
name=name)
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1997, in _placeholder
name=name)
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
op_def=op_def)
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2336, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1228, in __init__
self._traceback = _extract_stack()
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'train_data/X' with dtype float
[[Node: train_data/X = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
[[Node: add_5/_47 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_8_add_5", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
This is a code-specific error. My self.recognition_model
is actually linked to the placeholder self.train_data
through self.curr_batch_size
in self._sample_z()
. My solution is to re-link self.curr_batch_size
to the size of self.input_data
.
That's it. Happy Coding