TypeError:无法转换<class'类型的对象tensorflow.python.framework.稀疏_张量SparseTensor'到十

2024-04-25 07:26:08 发布

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

我试图将GraphSAGE的输入特征从一个numpy稠密矩阵转换为稀疏矩阵。 算法采用numpy矩阵并将其转换为TF变量,如下所示:

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

密矩阵对应的代码如下:

^{pr2}$

我试图用以下代码重写稀疏矩阵:

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]

当我试图这样做时,我遇到了以下错误:

 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.

有什么要调试的吗?TF版本是'1.13.1'


Tags: tonumpytf矩阵densefeaturessparsevalues

热门问题