Tensorflow:如何对多个不同类型的张量进行分组?

时间:2018-09-26 04:32:00

标签: python tensorflow tensorflow-datasets

问题

不幸的是,tf.group()不返回所计算操作的输出。我正在寻找一种方法来执行tf.group()的工作,但要获取那些张量的输出。 我希望可以在图表中完成所有操作,这样我就不必使用feed dict。

示例

发生这种情况的情况是,如果您要创建一个包含每个批处理的行号的文本解析器数据集。

start = 10
ts = tf.Variable(start,dtype=tf.int32)
ts_p1 = ts.assign_add(1)
ds = tf.data.TextLineDataset(filenames[0])
ds = ds.skip(start+1)
# Below is the line of interest
ds = ds.map(lambda line: tf.group([ts_p1,line]))
ds = ds.batch(1)
ds = ds.repeat()
it = ds.make_initializable_iterator()
nxt = it.get_next()

我尝试过的事情:

  1. tf.tuple()需要相同的类型
  2. tf.group()输出不包含值
  3. tf.identity_n()我的理解是,这是一个副本,因此性能不佳
  4. tf.gather()不是此问题的函数
  5. 将int32转换为字符串并追加到行(未找到支持将int强制转换为字符串)

0 个答案:

没有答案
相关问题