D.Giunchi
D.Giunchi

Reputation: 1960

tf.contrib.lookup.HashTable issue

I try to upgrade a cost function in which I need to calculate a lookup table:

tf_look_up_keys = tf.as_string(tf.range(0, int(N+1), dtype=tf.int32 ))
tf_look_up_values = ....an array of N+1 elements ....
tf.contrib.lookup.HashTable(tf.contrib.lookup.KeyValueTensorInitializer(tf_look_up_keys, tf_look_up_values), -1)

but when I start the session it tells this:

tensorflow.python.framework.errors_impl.FailedPreconditionError: Table not initialized.

>          [[Node: hash_table_Lookup = LookupTableFind[Tin=DT_STRING, Tout=DT_FLOAT, _class=["loc:@hash_table"],
> _device="/job:localhost/replica:0/task:0/cpu:0"](hash_table, AsString_1, hash_table/Const)]]

what should I do? In which way I can initialize (I tried to move up tf.global_variables_initializer() but it results in a long list of complains about other variables that before this modification were ok) Thank you, cheers

Upvotes: 2

Views: 3843

Answers (1)

user1454804
user1454804

Reputation: 1080

You need to inialize tables by tf.tables_initializer. Alternatively you can use MonitoredSession which does initialization for you.

Upvotes: 6

Related Questions