Try to search your question here, if you can't find : Ask Any Question Now ?

TypeError: Failed to convert object of type <class 'tensorflow.python.framework.sparse_tensor.SparseTensor'> to Tensor

HomeCategory: stackoverflowTypeError: Failed to convert object of type <class 'tensorflow.python.framework.sparse_tensor.SparseTensor'> to Tensor
john asked 3 weeks ago

I am trying to convert the input features of GraphSAGE from a numpy dense matrix to a sparse matrix.
The algorithm takes a numpy matrix and converts it to a TF variable as follows:

self.features = tf.sparse.SparseTensor(indices= features[0],values = features[1],dense_shape=features[2]) 

The code that corresponded to the dense matrix is show below:

hidden = [tf.nn.embedding_lookup(input_features, node_samples) for node_samples in samples]

I tried to rewrite it for a sparse matrix with the following code:

hidden = [tf.nn.embedding_lookup_sparse(input_features, sp_ids= tf.contrib.layers.dense_to_sparse(node_samples),sp_weights=None) for node_samples in samples]

When I try to do so, I encounter the following error:

 TypeError: Failed to convert object of type <class 'tensorflow.python.framework.sparse_tensor.SparseTensor'> to Tensor. Contents: SparseTensor(indices=Tensor("SparseTensor/indices:0", shape=(1078003, 2), dtype=int64), values=Tensor("SparseTensor/values:0", shape=(1078003,), dtype=float32), dense_shape=Tensor("SparseTensor/dense_shape:0", shape=(2,), dtype=int64)). Consider casting elements to a supported type.

Any ideas to debug? The TF version is ‘1.13.1’

1 Answers
Best Answer
naveen answered 3 weeks ago
Your Answer

19 + 5 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com