gpt4 book ai didi

tensorflow - 我可以将辅助输入传递给 Apache Beam PTransforms 吗?

转载 作者:行者123 更新时间:2023-12-02 02:56:19 24 4
gpt4 key购买 nike

我正在使用 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?感谢您的帮助

最佳答案

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

关于tensorflow - 我可以将辅助输入传递给 Apache Beam PTransforms 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49156159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com