Tensorflow密集梯度解释？ tensorflow 4 0 ``````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. "
``````

1. 此警告表示什么？看来我所做的事情导致所有梯度都变得密集，因此backprop正在进行密集矩阵计算
2. 如果是导致此问题的模型存在问题，如何识别并修复它？

Stack Overflow 收藏 评论  收藏 评论 ``````# dense
array = ['a', None, None, 'c']

# sparse
array = [(0, 'a'), (3, 'c')]
`````` 收藏 评论 ``````# Create the cells for the RNN network
lstm = tf.nn.rnn_cell.BasicLSTMCell(128)

# Get the output and state from dynamic rnn
output, state = tf.nn.dynamic_rnn(lstm, sequence, dtype=tf.float32, sequence_length = seqlen)

# Convert output to a tessor and reshape it
outputs = tf.reshape(tf.pack(output), [-1, lstm.output_size])

# Set partions to 2
num_partitions = 2

# The partitions argument is a tensor which is already fed to a placeholder.
# It is a 1-D tensor with the length of batch_size * max_sequence_length.
# In this partitions tensor, you need to set the last output idx for each seq to 1 and
# others remain 0, so that the result could be separated to two parts,
# one is the last outputs and the other one is the non-last outputs.
res_out = tf.dynamic_partition(outputs, partitions, num_partitions)

# prediction
preds = tf.matmul(res_out, weights) + bias
`````` 收藏 评论

• 社区规范
• 提出问题
• 进行投票
• 个人资料
• 优化问题
• 回答问题 关于我们 常见问题 内容许可 联系我们