When I read TensorFlow codes, I see people specify placeholders for the input arguments of the functions and then feed the input data in a session.run
. A trivial example can be like:
def sigmoid(z):
x = tf.placeholder(tf.float32, name='x')
sigmoid = tf.sigmoid(x)
with tf.Session() as session:
result = session.run(sigmoid, feed_dict={x:z})
return result
I wonder why don't they directly feed the z
into the tf.sigmoid(z)
and get rid of the placeholder x
?
If this is a best practice, what is the reason behind it?