import tensorflow as tf
indices=tf.constant([[1,3],[1,2],[4,2]])
dense=tf.sparse_to_dense(indices,[10,10], sparse_values=[1,2,3])
with tf.Session() as sess:
print(sess.run(dense))
问题现象:运行上面程序,报is out of order错误。但如果把indices=tf.constant([[1,3],[1,2],[4,2]])换成indices=tf.constant([[1,3],[1,4],[4,2]])就运行正常。
原因:在不设置参数validate_indices=False时,tf.sparse_to_dense要求indices必须是递增的。这个主要是为了方便函数检查indices是否有重复的。
如果要结局这个问题可以设置validate_indices=False,关闭这个功能。
import tensorflow as tf
indices=tf.constant([[1,3],[1,2],[4,2]])
dense=tf.sparse_to_dense(indices,[10,10], sparse_values=[1,2,3],validate_indices=False)
with tf.Session() as sess:
print(sess.run(dense))