module ‘tensorflow’ has no attribute ‘sparse_to_dense’

tensorflow2.0中把 sparse_to_dense去掉了
可以使用下面两个函数替代

1、先构造SparseTensor
tf.sparse.SparseTensor()
在这里插入图片描述
2、再将Sparse Tensor转Dense
tf.sparse.to_dense()

在这里插入图片描述
合在一起

sparse_temp = tf.sparse.SparseTensor(indices=tf.cast(full_indices, tf.int64),
                                     values=tf.cast(tf.reshape(values, [-1]), tf.int64),
                                     dense_shape=tf.cast(x.get_shape(), tf.int64))
to_substract = tf.sparse.to_dense(sparse_temp)

SparseTensor的参数必须为tf.int64

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐