tensorflow tf.placeholder

来源:互联网 发布:python base64.decode 编辑:程序博客网 时间:2024/06/11 22:22

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


Inserts a placeholder for a tensor that will be always fed.(可以理解为创建一个占位符,且这个占位符在运行前必须进行初始化,即f bd ed)

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


For example:

x = tf.placeholder(float, shape=(1024, 1024))y = tf.matmul(x, x)with tf.Session() as sess:  print sess.run(y)  # ERROR: will fail because x was not fed.  rand_array = np.random.rand(1024, 1024)  print sess.run(y, feed_dict={x: rand_array})  # Will succeed.

Args:
dtype: The type of elements in the tensor to be fed.(占位符里面的数据类型)
shape: The shape of the tensor to be fed (optional). If the shape is not specified, you can feed a tensor of any shape.(tensor的形状)
name: A name for the operation (optional).
Returns:


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

原创粉丝点击