October 2019
Intermediate to advanced
366 pages
12h 4m
English
A placeholder is a tensor that is fed at runtime. Usually, placeholders are used as input for models. Every input passed to a computational graph at runtime is fed with feed_dict. feed_dict is an optional argument that allows the caller to override the value of tensors in the graph. In the following snippet, the a placeholder is overridden by [[0.1,0.2,0.3]]:
import tensorflow as tfa = tf.placeholder(shape=(1,3), dtype=tf.float32)b = tf.constant([[10,10,10]], dtype=tf.float32)c = a + bsess = tf.Session()res = sess.run(c, feed_dict={a:[[0.1,0.2,0.3]]})print(res)>> [[10.1 10.2 10.3]]
If the size of the first dimension of the input is not known during the creation of the graph, TensorFlow can take care of it. Just set it to None ...
Read now
Unlock full access