关于TFX‘tensorflow-数据验证,我试图理解什么时候应该使用*Gen组件,还是使用TFDV提供的方法。
具体来说,让我困惑的是,我把它作为我的ExampleGen:
output = example_gen_pb2.Output(
split_config=example_gen_pb2.SplitConfig(splits=[
example_gen_pb2.SplitConfig.Split(name='train', hash_buckets=7),
example_gen_pb2.SplitConfig.Split(name='test', hash_buckets=2),
example_gen_pb2.SplitConfig.Split(name='eval', hash_buckets=1)
]))
example_gen = CsvExampleGen(input_base=os.path.join(base_dir, data_dir),
output_config=output)
context.run(example_gen)因此,我想,我想要从我的列车分割,而不是从原来的火车文件生成我的统计数据,所以我尝试:
statistics_gen = StatisticsGen(
examples=example_gen.outputs['examples'],
exclude_splits=['eval']
)
context.run(statistics_gen)一切都好。但是,我尝试推断我的模式(插入蜂鸣器声音):
schema = tfdv.infer_schema(statistics=statistics_gen)这会引起下面的错误。我完全希望它不是正确的类型,但是我不知道如何从StatsGen对象中提取适当的输出,以提供给infer_schema()方法。
或者,如果我只追求一个基于*Gen的组件结构,它就会生成,但我不知道如何正确地可视化模式、统计数据等。最后,我在这里使用tfdv.infer_schema()调用的原因是,如果您试图传递一个SchemaGen,那么类似的"display_schema()“调用就会出现错误。
以上错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-93ceafbcb04a> in <module>
----> 1 schema = tfdv.infer_schema(statistics=validate_stats)
2 tfdv.write_schema_text(schema, schema_location)
3
4 tfdv.display(infer_schema)
/usr/local/lib/python3.6/dist-packages/tensorflow_data_validation/api/validation_api.py in infer_schema(statistics, infer_feature_shape, max_string_domain_size, schema_transformations)
95 raise TypeError(
96 'statistics is of type %s, should be '
---> 97 'a DatasetFeatureStatisticsList proto.' % type(statistics).__name__)
98
99 # This will raise an exception if there are multiple datasets, none of which
TypeError: statistics is of type ExampleValidator, should be a DatasetFeatureStatisticsList proto.我真正想要理解的是,为什么我们有组件,比如SchemaGen和StatisticsGen,只有让TFDV要求我们使用内部函数才能从中获得价值。我认为它为交互式管道和非交互场景提供了条件,但我的谷歌让我不清楚。
如果有一种方法可以根据数据的分割来生成和查看统计数据,而不是依赖文件阅读器,我也想知道这一点。(如果不是显而易见的话,是的,我是TFX的新手)。
提亚
发布于 2020-10-04 19:59:34
我也是TFX的新手。你关于ExampleValidator的文章帮助了我,希望这能回答你的问题。
只使用组件来可视化模式
statistics_gen = StatisticsGen(
examples=example_gen.outputs['examples'],
exclude_splits=['eval']
)
context.run(statistics_gen)
schema_gen = SchemaGen(
statistics=statistics_gen.outputs['statistics'],
infer_feature_shape=True
)
context.run(schema_gen)
context.show(schema_gen.outputs['schema']) # this should allow you to to visualize your schema 使用组件+ TFDV可视化模式
看来我们不能直接使用StatisticsGen了。我们需要知道统计数据gen工件被保存到哪里,然后使用tfdv.load_statistics加载该工件
# get the stats artifact
stats_artifact = statistics_gen.outputs.statistics._artifacts[0]
# get base path
base_path = stats_artifact.uri
# get path to file
train_stats_file = os.path.join(base_path, 'train/stats_tfrecord') #only showing training as an example
# load stats
loaded_stats = tfdv.load_statistics(train_stats_file)
# generic and show schema
schema = tfdv.infer_schema(loaded_stats)
tfdv.display_schema(schema)https://stackoverflow.com/questions/64071574
复制相似问题