FailedPreconditionError:表已经初始化 [英] FailedPreconditionError: Table already initialized

查看:34
本文介绍了FailedPreconditionError:表已经初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am reading data from tfrecords with dataset api. I am converting string data to dummy data with following code.

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

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

But when i run my code, tensorflow is throwing following error.

tensorflow.python.framework.errors_impl.FailedPreconditionError:表已经初始化.[[节点:生成器/input_layer/SFR1 _indicator/SFR1 _lookup/hash_table/table_init= InitializeTableV2[Tkey=DT_STRING, Tval=DT_INT64](Generator/input_layer/SFR1_indicator/SFR1_lookup/hash_table,生成器/input_layer/SFR1 _indicator/SFR1 _lookup/Const,生成器/input_layer/SFR1 _indicator/SFR1 _lookup/ToInt64)]][[节点:Generator2/IteratorGetNext =IteratorGetNextoutput_shapes=[[?,10000,160]],output_types=[DT_FLOAT],_device="/job:localhost/replica:0/task:0/device:CPU:0"]]

tensorflow.python.framework.errors_impl.FailedPreconditionError: Table already initialized. [[Node: Generator/input_layer/SFR1 _indicator/SFR1 _lookup/hash_table/table_init = InitializeTableV2[Tkey=DT_STRING, Tval=DT_INT64](Generator/input_layer/SFR1 _indicator/SFR1 _lookup/hash_table, Generator/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/replica:0/task:0/device:CPU:0"]]

我尝试了多种组合来确定问题的根源.我知道当模型同时包含 tf.feature_column.categorical_column_with_vocabulary_listdataset api 时会出现此问题.如果我选择 TFRecordReader 而不是 dataset,代码正在运行.

I have tried many combinations to determine the source of problem. I understood that this problem occurs when model includes both tf.feature_column.categorical_column_with_vocabulary_list and dataset api. If i choose TFRecordReader instead of dataset, code is running.

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

When i search stackoverflow, I noticed that there is a similar issue. I am adding issue link below. As both problem are same, I didn't copy all my code. Below link includes enough data to explain my problem

数据集映射表中的 Tensorflow 特征列已初始化问题

谢谢.

推荐答案

我遇到了同样的问题.然后根据 Tensorflow 的警告修改了我的代码,它可以工作:

I came across the same issue. Then modified my code following the warning from Tensorflow and it works:

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

Creating lookup tables inside a function passed to Dataset.map() is not supported. Create each table outside the function, and capture it inside the function to use it.

希望它会有所帮助.

这篇关于FailedPreconditionError:表已经初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆