栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何处理用户警告:将稀疏的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]


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/646864.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号