简体   繁体   中英

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.

My question is, given a sparse tensor, or sparse tensor value, how do I retrieve the individual names for each comprising tensor, namely the indices tensor, values tensor and shape tensor? (Unless I happen to be misunderstanding the explanation in the quoted text and this isn't possible?)

You can access each of the three tensors within the SparseTensor object with:

# 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

As per documentation: https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor#attributes

You can not get their "names", but you can assign them to their own variables: values_of_sparse_tensor = some_sparse_tensor.values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM