【问题标题】:How to randomly select data from multiple aligned dataset in Tensorflow?如何从 Tensorflow 中的多个对齐数据集中随机选择数据?
【发布时间】:2019-02-07 05:35:26
【问题描述】:

假设我们有 2 个组中的 6 个文本文件,每个组由 3 个文件组成,例如,

  • 第 1 组:1.a、1.b、1.c
  • 第 2 组:2.a、2.b、2.c

给定一个固定阈值rand 和来自random 模块的random(),我希望得到3 个张量:

  • x 组:x_a、x_b、x_c

其中每个文件的行数相同且对齐,x_a 的第 n 行将是:

  • 第一步:'<nth line from 1.a>' if rand < random() else '<nth line from 2.a>'

x_b 和 x_c 的第 n 行也将是:

  • 第二步:<'nth line from 1.b>' if '<nth row of x_a from 1.a>' else '<nth line from 2.b>'
  • 第 3 步:<'nth line from 1.c>' if '<nth row of x_a from 1.a>' else '<nth line from 2.c>'(按照第 2 步但适用于 x_c)

使得 x_a、x_b 和 x_c 都对齐。

我使用的工具是tf.data.TextLineDataset,你能告诉我如何进行随机选择并保持选择轨迹吗?谢谢!

【问题讨论】:

    标签: python tensorflow-datasets


    【解决方案1】:

    =========================我的解决方案===================== ===

    我提供了一个跟踪文件来指导这 3 个文件。仍然欢迎其他解决方案!

    a1 = tf.data.TextLineDataset(afile1).map(...)
    b1 = tf.data.TextLineDataset(bfile1).map(...)
    c1 = tf.data.TextLineDataset(cfile1).map(...)
    ...
    index = tf.data.TextLineDataset(track_file).map(lambda line: tf.string_to_number(line, tf.int32))
    As = tf.data.Dataset.zip((index, a1, a2))
    Bs = tf.data.Dataset.zip((index, b1, b2))
    ...
    ax = As.map(lambda i, l, r: tf.where(i > 0, l, r))
    bx = As.map(lambda i, l, r: tf.where(i > 0, l, r))
    cx = As.map(lambda i, l, r: tf.where(i > 0, l, r))
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-30
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多