為將始終饋送的張量插入占位符。
用法
tf.compat.v1.placeholder(
dtype, shape=None, name=None
)
參數
-
dtype
要饋送的張量中元素的類型。 -
shape
要饋送的張量的形狀(可選)。如果未指定形狀,則可以輸入任何形狀的張量。 -
name
操作的名稱(可選)。
返回
-
一個
Tensor
,可用作提供值的句柄,但不直接評估。
拋出
-
RuntimeError
如果啟用了即刻執行
遷移到 TF2
警告:這個 API 是為 TensorFlow v1 設計的。繼續閱讀有關如何從該 API 遷移到本機 TensorFlow v2 等效項的詳細信息。見TensorFlow v1 到 TensorFlow v2 遷移指南有關如何遷移其餘代碼的說明。
此 API 與 Eager Execution 不兼容,並且tf.function.要遷移到 TF2,請重寫代碼以兼容 Eager Execution。檢查遷移指南更換Session.run
調用。在 TF2 中,您可以直接將張量傳遞給操作和層。如果要顯式設置輸入,另請參閱Keras 函數式 API關於如何使用tf.keras.Input取代tf.compat.v1.placeholder.tf.function參數也可以完成tf.compat.v1.placeholder.更多詳情請閱讀使用 tf.function 獲得更好的性能.
重要的:如果評估,此張量將產生錯誤。它的值必須使用 feed_dict
可選參數提供給 Session.run()
、 Tensor.eval()
或 Operation.run()
。
例如:
x = tf.compat.v1.placeholder(tf.float32, shape=(1024, 1024))
y = tf.matmul(x, x)
with tf.compat.v1.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.
相關用法
- Python tf.compat.v1.placeholder_with_default用法及代碼示例
- Python tf.compat.v1.profiler.Profiler用法及代碼示例
- Python tf.compat.v1.parse_example用法及代碼示例
- Python tf.compat.v1.py_func用法及代碼示例
- Python tf.compat.v1.pad用法及代碼示例
- Python tf.compat.v1.profiler.ProfileOptionBuilder用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python tf.compat.v1.Variable.eval用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.layers.conv3d用法及代碼示例
- Python tf.compat.v1.strings.length用法及代碼示例
- Python tf.compat.v1.data.Dataset.snapshot用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.reduce用法及代碼示例
- Python tf.compat.v1.feature_column.categorical_column_with_vocabulary_file用法及代碼示例
- Python tf.compat.v1.data.TextLineDataset.from_tensors用法及代碼示例
- Python tf.compat.v1.variable_scope用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.as_numpy_iterator用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.placeholder。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。