tf.placeholder

3912 ワード

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は、値を提供するハンドルとして使用できますが、直接評価することはできません.