簡體   English   中英

TFX - 如何檢查來自 CsvExampleGen 的記錄

[英]TFX - How to inspect records from CsvExampleGen

問題

如何檢查加載到 TFX CsvExampleGen 中的數據?

CSV

california_housing_train.csv的前 3 行如下所示。

經度 緯度 住房中位數年齡 total_rooms total_bedrooms 人口 家庭 收入中位數 中值房屋價值
-122.05 37.37 27 3885 661 1537 606 6.6085 344700
-118.3 34.26 43 1510 310 809 277 3.599 176500
-117.81 33.78 27 3589 507 1484 495 5.7934 270500

CSVExampleGen

CSV 被加載到 CsvExampleGen 中。 據我了解,XXXExampleGen 是生成 tf.Record 實例,因此我想知道是否有一種方法可以遍歷 CsvExampleGen 中的記錄。

from tfx.components import (
    CsvExampleGen
)
housing = CsvExampleGen("sample_data/california_housing_train.csv")
housing
----------
CsvExampleGen(
    spec: <tfx.types.standard_component_specs.FileBasedExampleGenSpec object at 0x7fcd90435450>,
    executor_spec: <tfx.dsl.components.base.executor_spec.BeamExecutorSpec object at 0x7fcd90435850>,
    driver_class: <class 'tfx.components.example_gen.driver.FileBasedDriver'>,
    component_id: CsvExampleGen,
    inputs: {},
    outputs: {
        'examples': OutputChannel(artifact_type=Examples,
        producer_component_id=CsvExampleGen,
        output_key=examples,
        additional_properties={},
        additional_custom_properties={})
    }
)

實驗

for record in housing.outputs['examples']:
    print(record)

----> 1 中的 TypeError Traceback (last last call last) for record in Housing.outputs['examples']: 2 print(record)

TypeError:“OutputChannel”對象不可迭代

您是否有機會查看教程中的這一部分,其中解釋了如何顯示ExampleGen組件的工件? 您可以修改下面的代碼(來源: TFX 教程)以實現相同的目的。

# Get the URI of the output artifact representing the training examples, which is a directory
train_uri = os.path.join(example_gen.outputs['examples'].get()[0].uri, 'Split-train')

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

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM