In the previous example, we computed the sum of two vectors. However, we defined the value of those vectors when creating the graph. If we wanted to use variables instead, we could have used tf1.placeholder:
a = tf1.placeholder(dtype=tf.int32, shape=(None,))
b = tf1.placeholder(dtype=tf.int32, shape=(None,)) c = a + b
with tf1.Session() as sess:
result = sess.run(c, feed_dict={
a: [1, 2, 3],
b: [1, 1, 1]
})
In TensorFlow 1, placeholders are mostly used to provide input data. Their type and shape have to be defined. In our example, the shape is (None,) because we may want to run the operation on vectors of any size. When running the graph, we have to provide specific values for our placeholders. This is why we use the feed_dict argument in sess.run, passing the content of variables as a dictionary, with the placeholders as keys. Failing to provide a value for all placeholders would cause an exception.
Before TensorFlow 2, placeholders were used to provide...