如何从中删除显式0斯巴塞传感器?

2024-09-29 02:28:34 发布

您现在位置:Python中文网/ 问答频道 /正文

在我的模型训练的每一个阶段中,tf.SparseTensor都会改变它的值,使其具有更明确的零。去除这些显式零点将使显式边的数目减少,从而使整个计算更快。你知道吗

所以,我需要一种从tf.SparseTensor中删除显式零的方法,以使它更“苗条”。有人知道怎么做吗?你知道吗


Tags: 方法模型tf阶段数目苗条零点sparsetensor
1条回答
网友
1楼 · 发布于 2024-09-29 02:28:34

您可以使用^{}操作解决此问题:

st = ...  # A `tf.SparseTensor` object.

# Compute a vector of booleans indicating which values of `st` should be dropped
# (if False) or retained (if True)
is_nonzero = tf.not_equal(st.values, 0)

# `tf.sparse_retain()` computes a new `tf.SparseTensor` with the specified values
# retained in the output.
st_without_zeros = tf.sparse_retain(st, is_nonzero)

相关问题 更多 >