我運行到一個問題,即鏈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