TFX组件CsvExampleGen始终产生带有空输出和输入的示例

问题描述

我可以在没有错误消息的情况下运行CsvexampleGen,但是结果示例的输出(和输入)始终为空。

我正在使用tfx == 0.24.0。

要使用CsvexampleGen读取CSV文件,请按照文档和教程(包括https://www.tensorflow.org/tfx/guide/examplegen)和tfx 0.23.0 / 0.24.0(https://github.com/tensorflow/tfx/releases)的发行说明进行以下操作的代码足以读取CVS文件

from tfx.components import CsvexampleGen
example_gen = CsvexampleGen(input_base=data_path)

其中“ data_path”标识包含CVS文件的目录。 (请注意,该代码与官方文档不同,因为它不使用“ external_input”;而是遵循0.23.0发行说明中记录的新界面。)

从教程中我收集到一个简单的CVS文件足以满足测试要求(尽管我尝试使用最多7个文件)。

我没有收到任何错误消息(除非我没有GPU,否则系统会告诉我忽略该错误消息);但是,结果结构的输出(和输入)为空(分别为空列表和空set / dict)。我认为它们不应为空。

找到并触摸了有问题的CSV文件,因为如果在其中引入错误(如一行中的另一列),则会收到错误消息。

我尝试了使用独立功能以及在管道内部(为简单起见,使用BeamDagRunner运行)。管道确实生成Metadata.db,但是我在那里找不到CSV数据的任何痕迹(例如列名)。将StatisticsGen添加到管道中无济于事。

我尝试使用带有和不带有列标题的虹膜数据集。我还尝试在data_path中使用多达7个小型人工CVS文件,或者使用纯数字和混合数字/类别数据,或者使用逗号和分号作为分隔符。结果总是一样。

我是否对代码或某些配置或库有疑问?

这是完整的代码(尽可能相关):

PIPELINE_NAME = "X-pipeline-iris2"
BASE_PATH = r"C:\***\FX_Experiments"
BASE_PATH_PIPELINE = os.path.join(BASE_PATH,"pipeline")
BASE_PATH_TESTS = os.path.join(BASE_PATH,"tests")
PIPELINE_ROOT = os.path.join(BASE_PATH_PIPELINE,"output")
MetaDATA_PATH = os.path.join(BASE_PATH_PIPELINE,"tfx_Metadata",PIPELINE_NAME,"Metadata.db")
DATA_PATH = os.path.join(BASE_PATH_TESTS,"iris2")
ENABLE_CACHE = True


def create_pipeline(
        pipeline_name: Text,pipeline_root: Text,data_path: Text,enable_cache: bool,Metadata_connection_config: Optional[Metadata_store_pb2.ConnectionConfig] = None,beam_pipeline_args: Optional[List[Text]] = None
):
    components = []

    example_gen = CsvexampleGen(input_base=data_path)
    components.append(example_gen)

    stat_gen = StatisticsGen(examples=example_gen.outputs['examples'])
    components.append(stat_gen)

    return pipeline.Pipeline(
        pipeline_name = pipeline_name,pipeline_root = pipeline_root,components = components,enable_cache = enable_cache,Metadata_connection_config = Metadata_connection_config,beam_pipeline_args = beam_pipeline_args
    )

def run_pipeline():
    this_pipeline = create_pipeline(
        pipeline_name=PIPELINE_NAME,pipeline_root=PIPELINE_ROOT,data_path=DATA_PATH,enable_cache=ENABLE_CACHE,Metadata_connection_config=Metadata.sqlite_Metadata_connection_config(MetaDATA_PATH)
    )
    BeamDagRunner().run(this_pipeline)

也可能有用:记录器信息:

INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Component CsvexampleGen depends on [].
INFO:absl:Component CsvexampleGen is scheduled.
INFO:absl:Component StatisticsGen depends on ['Run[CsvexampleGen]'].
INFO:absl:Component StatisticsGen is scheduled.
INFO:absl:Component CsvexampleGen is running.
INFO:absl:Running driver for CsvexampleGen
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:select span and version = (0,None)
INFO:absl:latest span and version = (0,None)
INFO:absl:Running publisher for CsvexampleGen
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component CsvexampleGen is finished.
INFO:absl:Component StatisticsGen is running.
...

解决方法

Felix,如果您遵循指南,您可能会在笔记本中运行您的代码。如果您想直接查看结果,您必须使用 InteractiveContext 启用 TFX 交互。

https://www.tensorflow.org/tfx/api_docs/python/tfx/orchestration/experimental/interactive/interactive_context/InteractiveContext

context = InteractiveContext()
example_gen = CsvExampleGen(input_base='/content/data')
context.run(example_gen)