Я предварительно обрабатываю данные для TensorFlow с помощью Apache Beam. Я хотел бы выбрать количество осколков 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? Спасибо за помощь