【发布时间】:2020-07-14 17:20:32
【问题描述】:
我有一堆 tensorflow 记录(这些不是我创建的)。但是,我需要通过加入另一个数据源(一个大查询表)来添加更多功能。如何编辑 tf 记录,将其转换为 TfDataset 还是需要以某种方式将其转换为 pandas 数据帧并加入数据并作为 tfrecord 写出?谁有例子?
【问题讨论】:
标签: tensorflow apache-beam tfrecord
我有一堆 tensorflow 记录(这些不是我创建的)。但是,我需要通过加入另一个数据源(一个大查询表)来添加更多功能。如何编辑 tf 记录,将其转换为 TfDataset 还是需要以某种方式将其转换为 pandas 数据帧并加入数据并作为 tfrecord 写出?谁有例子?
【问题讨论】:
标签: tensorflow apache-beam tfrecord
假设您在 TfRecord 中有 TFExample,那么一种方法是使用 beam.io.tfrecordio.ReadFromTFRecord 和 tf 解析函数:
...
pipeline
| "ReadMetadata" >> beam.io.tfrecordio.ReadFromTFRecord(
file_pattern=<file pattern>)
| "ParseMetadataFile" >> beam.ParDo(_parseExamples())
class _parseExamples(beam.DoFn):
def __init__(self):
beam.DoFn.__init__(self)
def process(self, element, feature_dict) -> tf.train.Example:
example = tf.train.Example.FromString(element)
# Or something like...
# example = tf.io.parse_single_example(element, feature_dict)
# Then something like
# t = example.features.feature['new']
# t = tf.train.Feature(int64_list=tf.train.Int64List(value=[1]))
yield example
关于 TFRecord 和 tf.Example 的其他非光束特定说明
【讨论】: