【发布时间】: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