你如何获得稀疏张量中使用的张量的名称?
How do you get the names of tensors used in a sparse tensor?
TensorFlow represents a sparse tensor as three separate dense tensors: indices, values, and dense_shape. In Python, the three tensors are collected into a SparseTensor class for ease of use. If you have separate indices, values, and dense_shape tensors, wrap them in a SparseTensor object before passing to the ops below.
我的问题是,给定一个稀疏张量或稀疏张量值,我如何检索每个包含张量的单独名称,即索引张量、值张量和形状张量? (除非我碰巧误解了引用文本中的解释,这是不可能的?)
您可以通过以下方式访问 SparseTensor 对象中的三个张量中的每一个:
# Here some_sparse_tensor is an object of the tf.sparse.SparseTensor class
some_sparse_tensor.indices
some_sparse_tensor.values
some_sparse_tensor.dense_shape
根据文档:
https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor#attributes
你无法得到它们的“名字”,但你可以将它们赋值给它们自己的变量:
values_of_sparse_tensor = some_sparse_tensor.values
TensorFlow represents a sparse tensor as three separate dense tensors: indices, values, and dense_shape. In Python, the three tensors are collected into a SparseTensor class for ease of use. If you have separate indices, values, and dense_shape tensors, wrap them in a SparseTensor object before passing to the ops below.
我的问题是,给定一个稀疏张量或稀疏张量值,我如何检索每个包含张量的单独名称,即索引张量、值张量和形状张量? (除非我碰巧误解了引用文本中的解释,这是不可能的?)
您可以通过以下方式访问 SparseTensor 对象中的三个张量中的每一个:
# Here some_sparse_tensor is an object of the tf.sparse.SparseTensor class
some_sparse_tensor.indices
some_sparse_tensor.values
some_sparse_tensor.dense_shape
根据文档: https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor#attributes
你无法得到它们的“名字”,但你可以将它们赋值给它们自己的变量:
values_of_sparse_tensor = some_sparse_tensor.values