I'm using the tf.data.Dataset API in conjunction with tf.contrib.lookup.index_table_from_tensor.
My dataset was created like this:
dataset = tf.data.Dataset.from_tensor_slices(({'reviews': x}, y)))
Here's what I'm doing:
data_table = tf.contrib.lookup.index_table_from_tensor(tf.constant(data_vocab))
labels_table = tf.contrib.lookup.index_table_from_tensor(tf.constant(labels_vocab))
Then I map a preprocessing function across my dataset:
def preprocess(x, y):
# split on whitespace
x['reviews'] = tf.string_split([x['reviews']])
# turn into integers
return data_table.lookup(x['reviews']), labels_table.lookup(y)
All good so far. However, when I try to pass my dataset to my Keras model for training, I get:
tensorflow.python.framework.errors_impl.FailedPreconditionError: Table not initialized.
I googled around and people suggest that I need to include:
sess = tf.Session()
sess.run(tf.tables_initializer())
But now I get:
tensorflow.python.framework.errors_impl.FailedPreconditionError: Table not initialized.
[[Node: hash_table_Lookup = LookupTableFindV2[Tin=DT_STRING, Tout=DT_INT64](hash_table_lookup_placeholder, StringSplit:1, hash_table_lookup_placeholder_1)]]
[[Node: IteratorGetNext_1 = IteratorGetNext[output_shapes=[[?,?], [?,20]], output_types=[DT_INT64, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](Iterator_1)]]
Any idea why my lookup table is still not initialized / how to fix this?
Thanks!