為將始終饋送的稀疏張量插入占位符。
用法
tf.compat.v1.sparse_placeholder(
dtype, shape=None, name=None
)
參數
-
dtype
要饋送的張量中values
元素的類型。 -
shape
要饋送的張量的形狀(可選)。如果未指定形狀,則可以輸入任何形狀的稀疏張量。 -
name
操作前綴的名稱(可選)。
返回
-
一個
SparseTensor
,可用作提供值的句柄,但不直接評估。
拋出
-
RuntimeError
如果啟用了即刻執行
重要的:如果評估,此稀疏張量將產生錯誤。它的值必須使用 feed_dict
可選參數提供給 Session.run()
、 Tensor.eval()
或 Operation.run()
。
例如:
x = tf.compat.v1.sparse.placeholder(tf.float32)
y = tf.sparse.reduce_sum(x)
with tf.compat.v1.Session() as sess:
print(sess.run(y)) # ERROR:will fail because x was not fed.
indices = np.array([[3, 2, 0], [4, 5, 1]], dtype=np.int64)
values = np.array([1.0, 2.0], dtype=np.float32)
shape = np.array([7, 9, 2], dtype=np.int64)
print(sess.run(y, feed_dict={
x:tf.compat.v1.SparseTensorValue(indices, values, shape)})) # Will
succeed.
print(sess.run(y, feed_dict={
x:(indices, values, shape)})) # Will succeed.
sp = tf.sparse.SparseTensor(indices=indices, values=values,
dense_shape=shape)
sp_value = sp.eval(session=sess)
print(sess.run(y, feed_dict={x:sp_value})) # Will succeed.
@compatibility{eager} 占位符與即刻執行不兼容。
相關用法
- Python tf.compat.v1.sparse_to_dense用法及代碼示例
- Python tf.compat.v1.sparse_segment_sum用法及代碼示例
- Python tf.compat.v1.sparse_split用法及代碼示例
- Python tf.compat.v1.sparse_reduce_max用法及代碼示例
- Python tf.compat.v1.sparse_merge用法及代碼示例
- Python tf.compat.v1.sparse_concat用法及代碼示例
- Python tf.compat.v1.sparse_add用法及代碼示例
- Python tf.compat.v1.sparse_reduce_sum用法及代碼示例
- Python tf.compat.v1.space_to_batch用法及代碼示例
- Python tf.compat.v1.space_to_depth用法及代碼示例
- Python tf.compat.v1.strings.length用法及代碼示例
- Python tf.compat.v1.scatter_min用法及代碼示例
- Python tf.compat.v1.summary.merge用法及代碼示例
- Python tf.compat.v1.size用法及代碼示例
- Python tf.compat.v1.scatter_add用法及代碼示例
- Python tf.compat.v1.summary.FileWriter用法及代碼示例
- Python tf.compat.v1.scatter_div用法及代碼示例
- Python tf.compat.v1.string_split用法及代碼示例
- Python tf.compat.v1.squeeze用法及代碼示例
- Python tf.compat.v1.set_random_seed用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.sparse_placeholder。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。