我试图将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'
目前没有回答
相关问题 更多 >
编程相关推荐