TensorFlow占位符:tf.placeholder

2018-11-09 11:33 更新
tf.placeholder 函數
placeholder(
    dtype,
    shape=None,
    name=None
)

定義在:tensorflow/python/ops/array_ops.py

請參閱指南:輸入和讀取器>占位符

插入一個張量的占位符,這個張量將一直被提供.

注意:如果計算,該張量將產生一個錯誤,其值必須使用 feed_dict 可選參數來進行 session . run()、Tensor.eval() 或 oper.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.

參數:

  • dtype:要輸入的張量中元素的類型.
  • shape:要輸入的張量的形狀(可選).如果未指定形狀,則可以輸入任何形狀的張量.
  • name:操作的名稱(可選).

返回:

一個可能被用作提供一個值的句柄的張量,但不直接計算.

以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號