Обработвам предварително данни за 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? Благодаря за помощта