hakan.t
hakan.t

Reputation: 95

FailedPreconditionError: Table already initialized

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")))

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

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"]]

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.

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 feature columns in Dataset map Table already initialized issue

Thanks.

Upvotes: 2

Views: 1690

Answers (2)

Vikas Sharma
Vikas Sharma

Reputation: 451

This is issue with earlier version of TensorFlow, updating to TF2.0 should resolve this.

pip install --upgrade tensorflow

Upvotes: 0

James Chen
James Chen

Reputation: 21

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

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.

Hope it would help.

Upvotes: 2

Related Questions