Closed bsat007 closed 6 years ago
Hi @bsat007,
The issue is that "[tf.global_variables_initializer(), tf.tables_initializer()]" are functions that add new ops/nodes in the current graph. But the current graph was different than the graph where sess
was created.
This should work:
module_path = "https://tfhub.dev/google/universal-sentence-encoder/2"
g = tf.Graph()
with g.as_default():
similarity_input_placeholder = tf.placeholder(tf.string, shape=(None))
embed = hub.Module(module_path, trainable=True)
encoding_tensor = embed(similarity_input_placeholder)
init_op = tf.group([tf.global_variables_initializer(), tf.tables_initializer()])
g.finalize()
sess = tf.Session(graph=g)
sess.run(init_op)
sess.run(encoding_tensor, feed_dict={similarity_input_placeholder:["hello earth", "hello mars"]})
But I would highly recomend you use MonitoredSession:
module_path = "https://tfhub.dev/google/universal-sentence-encoder/2"
g = tf.Graph()
with g.as_default():
similarity_input_placeholder = tf.placeholder(tf.string, shape=(None))
embed = hub.Module(module_path, trainable=True)
encoding_tensor = embed(similarity_input_placeholder)
sess = tf.train.MonitoredSession(graph=g) # This finalizes the graph and runs initializers.
sess.run(encoding_tensor, feed_dict={similarity_input_placeholder:["hello earth", "hello mars"]})
I am very new to Tensorflow, I am trying to use text module.
Getting this error:
What am I doing wrong?