【问题标题】:Can I pass side inputs to Apache Beam PTransforms?我可以将侧面输入传递给 Apache Beam PTransforms 吗?
【发布时间】:2018-03-07 15:55:58
【问题描述】:

我正在使用 Apache Beam 为 TensorFlow 预处理数据。我想根据我的数据集中的示例数量来选择 TFRecord 分片的数量。相关部分代码为:

EXAMPLES_PER_SHARD = 5.0
num_tfexamples = tfexample_strs | "count tf examples" >> beam.combiners.Count.Globally()
num_shards = num_tfexamples | ("compute number of shards" >>
                               beam.Map(lambda num_examples: int(math.ceil(num_examples / EXAMPLES_PER_SHARD))))
_ = tfexample_strs | ("output to tfrecords" >>
                      beam.io.WriteToTFRecord(OUTPUT_DIR, num_shards=beam.pvalue.AsSingleton(num_shards)))

堆栈跟踪失败:

File "/usr/local/lib/python2.7/dist-packages/apache_beam/io/iobase.py", line 1011, in start_bundle
    self.counter = random.randint(0, self.count - 1)
TypeError: unsupported operand type(s) for -: 'AsSingleton' and 'int' [while running 'output VALIDATION to tfrecords/Write/WriteImpl/ParDo(_RoundRobinKeyFn)']

我在 PTransform 的类定义中看到了这一行

# By default, transforms don't have any side inputs.
side_inputs = ()

是否可以将侧面输入传递给 PTransforms?感谢您的帮助

【问题讨论】:

    标签: tensorflow google-cloud-dataflow apache-beam


    【解决方案1】:

    WriteToTFRecord 不支持为num_shards 使用侧面输入。理论上没有什么能阻止它这样做(在 Java SDK 中是可能的),它只是没有在 Python SDK 中实现。随时提交JIRA

    【讨论】:

      猜你喜欢
      • 2018-05-11
      • 2017-07-13
      • 2013-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-07
      相关资源
      最近更新 更多