i2tutorials

TensorFlow Placeholder

TensorFlow Placeholder

placeholder is a variable that gets assigned with data. It allows us to create our operations and build our computation graph and then feed data into the graph through these placeholders.

It  feeds the tensor to initialize the data to flow

The syntax is

:tf.placeholder(dtype,shape=None,name=None )

 

arguments:

1. dtype:Type of data

2. shape(Optional): placeholder’s dimension. By default, shape of the data

3. name(Optional): placeholder’s Name

tf.placeholder(tf.float32, name

"data_placeholder_a")print(data_placeholder_a)

 

Output

Tensor("data_placeholder_a:0", dtype=float32)

 

 tf.placeholder:

  tf.placeholder(dtype,shape=None,name=None)

 

Important: This tensor will produce an error until  Its value must be fed using the feed_dict optional argument to Session.run(), Tensor.eval(), or Operation.run().

For Example:

A1 = tf.placeholder(tf.float32, shape=(1024, 1024))

A2 = tf.matmul(A1,A2)



with tf.Session() as sess:

  print(sess.run(A2))

 

# ERROR: will fail because A1 was not fed.
rand_array = np.random.rand(1024, 1024)
print(sess.run(A2, feed_dict={A1: rand_array}))  # Will succeed.

Tensorflow 11 (i2tutorials)

Args:

dtype: The type of elements to be fed.

shape(optional): The shape of the tensor to be fed you can feed a tensor of any shape.

name(optional): A name for the operation .

 

Returns:

A Tensor that may be used as a handle for feeding a value, but not evaluated directly.

 

Raises:  (RuntimeError)if eager execution is enabled

Eager Compatibility

Placeholders are not compatible with eager execution.

 

 

Exit mobile version