Placeholders in Tensorflow
A placeholder is a variable in Tensorflow to which data will be assigned sometime later on. It enables us to create processes or operations without the requirement for data. Data is fed into the placeholder as the session starts, and the session is run. We can feed in data into tensorflow graphs using placeholders.
Syntax: tf.compat.v1.placeholder(dtype, shape=None, name=None)
- dtype: the datatype of the elements in the tensor that will be fed.
- shape : by default None. The tensor’s shape that will be fed , it is an optional parameter. One can feed a tensor of any shape if the shape isn’t specified.
- name: by default None. The operation’s name , optional parameter.
A Tensor that can be used to feed a value but cannot be evaluated directly.
after executing the operation: [20. 30. 40. 50.]
- Eager mode is disabled in case there are any errors.
- A placeholder is created using tf.placeholder() method which has a dtype ‘tf.float32’, None says we didn’t specify any size.
- Operation is created before feeding in data.
- The operation adds 10 to the tensor.
- A session is created and started using tf.Session().
- Session.run takes the operation we created and data to be fed as parameters and it returns the result.
after executing the operation: [[ 1. 4. 9.] [16. 25. 36.] [49. 64. 81.]]
My Personal Notes arrow_drop_up
Please Login to comment...