我现在已经在几个项目中使用了 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 的痛苦实际上可能更糟......