0

我现在已经在几个项目中使用了 TFX,并且发现调试 tf.transform 极具挑战性。我最初的几个管道是在 Airflow 中组成的,这需要我提交代码、推送到 Airflow、运行 Dag 以获取代码反馈。这非常糟糕,因为它在迭代开发循环中至少延迟了 2 分钟。在示例中提供的笔记本中使用 tfx 有很大帮助,因为它将时间缩短到大约一分钟。

如果代码有效,您可以使用这样的代码来挖掘生成的 protobuf 以获取输出

%%skip_for_export
import tensorflow as tf

train_transform_uri = os.path.join(transform.outputs['transformed_examples'].get()[0].uri, 'train')

# Get the list of files in this directory (all compressed TFRecord files)
tfrecord_filenames = [os.path.join(train_transform_uri, name)
                      for name in os.listdir(train_transform_uri)]

# Create a `TFRecordDataset` to read these files
dataset = tf.data.TFRecordDataset(tfrecord_filenames, compression_type="GZIP")

# Iterate over the first few tfrecords and decode them.
for tfrecord in dataset.take(5):
    serialized_example = tfrecord.numpy()
    example = tf.train.Example()
    example.ParseFromString(serialized_example)
    pprint.pprint(example)

人们还有其他方法可以用来解决这种痛苦吗?我在做错事吗?我绝对看到了使用 Transform 来避免训练/服务倾斜疼痛的好处,但我觉得 Transform 的痛苦实际上可能更糟......

4

1 回答 1

1

我在寻找完全相同问题的解决方案时遇到了这个问题。我开始研究已经两周了,但我仍然没有发现比打印解码示例更好的方法。所以“有没有其他方法”问题的答案是:很可能没有。

于 2021-08-24T11:14:35.523 回答