FailedPreconditionError:表已初始化

问题描述 投票:2回答:1

我正在使用数据集api从tfrecords中读取数据。我正在使用以下代码将字符串数据转换为虚拟数据。

SFR1 = tf.feature_column.indicator_column(
    tf.feature_column.categorical_column_with_vocabulary_list("SFR1 ",
                                                             vocabulary_list=("1", "2")))

但是当我运行我的代码时,tensorflow会抛出以下错误。

tensorflow.python.framework.errors_impl.FailedPreconditionError:表已初始化。 [[节点:生成器/ input_layer / SFR1 _indicator / SFR1 _lookup / hash_table / table_init = InitializeTableV2 [Tkey = DT_STRING,Tval = DT_INT64](生成器/ input_layer / SFR1 _indicator / SFR1 _lookup / hash_table,生成器/ input_layer / SFR1 _indicator / SFR1 _lookup / Const,Generator / input_layer / SFR1 _indicator / SFR1 _lookup / ToInt64)]] [[Node:Generator2 / IteratorGetNext = IteratorGetNextoutput_shapes = [[?,10000,160]],output_types = [DT_FLOAT],_ device =“/ job:localhost /复制:0 /任务:0 /装置:CPU:0" ]]

我尝试了很多组合来确定问题的根源。我明白当模型包括tf.feature_column.categorical_column_with_vocabulary_listdataset api时会出现这个问题。如果我选择TFRecordReader而不是dataset,代码正在运行。

当我搜索stackoverflow时,我注意到存在类似的问题。我在下面添加问题链接。由于两个问题都相同,我没有复制我的所有代码。以下链接包含足够的数据来解释我的问题

Tensorflow feature columns in Dataset map Table already initialized issue

谢谢。

python-3.x tensorflow tensorflow-datasets
1个回答
1
投票

我遇到了同样的问题。然后根据Tensorflow的警告修改了我的代码,它的工作原理如下:

不支持在传递给Dataset.map()的函数内创建查找表。在函数外部创建每个表,并在函数内捕获它以使用它。

希望它会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.