I am constructing a computation graph with topology that varies based on some hyperparameters. At some point, a concatenation takes place:
c = tf.concat([a, b], axis=-1)
The tensor a
has shape (None, m)
.
The tensor b
has shape (None, n)
where n
depends on the hyperparameters. For one value of the hyperparameters, the tensor b
should be conceptually empty, e.g. we want c
and a
to be the same.
I can build the graph successfully with the following:
b = tf.placeholder(tf.float32, (None, 0), name="Empty")
but then, if I run a session, TensorFlow raises an InvalidArgumentError
stating:
You must feed a value for placeholder tensor 'Empty' with dtype float and shape [?,0]
Is there any way to construct a tensor that will behave as empty in the concat
operation, but does not require feeding a spurious input?
Obviously, I'm aware that I could just add a special case, wrapper, etc. in the code where I construct the graph. I'm hoping to avoid that.
Full code:
import tensorflow as tf
import numpy as np
a = tf.placeholder(tf.float32, (None, 10))
b = tf.placeholder(tf.float32, (None, 0), name="Empty")
c = tf.concat([a, b], axis=-1)
assert c.shape.as_list() == [None, 10]
with tf.Session() as sess:
a_feed = np.zeros((100, 10))
c = sess.run(c, {a : a_feed})