我运行到一个问题,即链tf.gather()
索引产生以下警告:Tensorflow:链接tf.gather()产生IndexedSlices警告
/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gradients.py:90: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
"Converting sparse IndexedSlices to a dense Tensor of unknown shape. "
该场景出现时一个层索引到输入层,进行对相应切片进行一些操作,然后下一层索引到结果中。这里有一个代表性的例子:
import tensorflow as tf
## 10-Dimensional data will be fed to the model
X = tf.placeholder(tf.float32, [10, None])
## W works with the first 3 features of a sample
W = tf.Variable(tf.ones([5, 3]))
Xi = tf.gather(X, [0,1,2])
mm = tf.matmul(W, Xi)
## Indexing into the result produces a warning during backprop
h = tf.gather(mm, [0,1])
...
train_step = tf.train.AdamOptimizer(1e-4).minimize(loss)
警告出现时的train_step
定义,如果第二tf.gather()
呼叫被带走消失。如果X
提供了明确数量的样本(例如,[10, 1000]
),警告也会消失。
想法?
谢谢。这就说得通了。我实际上能够重构我的代码以使用'tf.dynamic_partition()'而不是'tf.gather()',它除了避免警告外,还提供了更清晰的实现。 –
@ArtemSokolov请你分享你的解决方案与dynamic_partition? – ryuzakinho