如何处理用户警告:将稀疏的IndexedSlices转换为形状未知的密集张量

如何处理用户警告:将稀疏的IndexedSlices转换为形状未知的密集张量,第1张

如何处理用户警告:将稀疏的IndexedSlices转换为形状未知的密集张量

设法通过使用tf.dynnamic_partition而不是tf.gather解决了这个问题。我这样替换了上面的代码:

# Flatten batch elements to rank-2 tensor where 1st max_length rows belong to first batch element and so forthall_timesteps = tf.reshape(raw_output, [-1, n_dim])  # (batch_size*max_length, n_dim)# Indices to last element of each sequence.# Index to first element is the sequence order number times max sequence length.# Index to last element is the index to first element plus sequence length.row_inds = tf.range(0, batch_size) * max_length + (seq_len - 1)# Creating a vector of 0s and 1s that will specify what timesteps to choose.partitions = tf.reduce_sum(tf.one_hot(row_inds, tf.shape(all_timesteps)[0], dtype='int32'), 0)# Selecting the elements we want to choose.last_timesteps = tf.dynamic_partition(all_timesteps, partitions, 2)  # (batch_size, n_dim)last_timesteps = last_timesteps[1]


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5649078.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存