tf.placeholder

tf.placeholder

https://github.com/tensorflow/docs/tree/r1.4/site/en/api_docs/api_docs/python/tf
site/en/api_docs/api_docs/python/tf/placeholder.md

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

Defined in tensorflow/python/ops/array_ops.py.
See the guides: Inputs and Readers > Placeholders

Inserts a placeholder for a tensor that will be always fed.
插入一个占位符,用于总是被馈送的张量。

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().
如果评估,该张量将产生错误。它的值必须使用 feed_dict 可选参数提供给 Session.run()Tensor.eval()Operation.run()

x = tf.placeholder(tf.float32, 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.

1. 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. (要馈送的张量的形状 (可选)。如果未指定形状,则可以提供任何形状的张量。)
  • name: A name for the operation (optional). (操作的名称 (可选)。)

2. Returns

A Tensor that may be used as a handle for feeding a value, but not evaluated directly.
一个 Tensor,可以用作提供值的句柄,但不能直接评估。

你可能感兴趣的:(TensorFlow)