tensorflow集线器存在问题:表未初始化



当我遇到以下问题时,我正试图将tf_hub用于大型通用语句编码器:

FailedPreconditionError (see above for traceback): Table not initialized.

TensorFlow似乎认为我没有运行init-op,但实际上,我已经运行了init-op:

embed = hub.Module("https://tfhub.dev/google/universal-sentence-encoder-large/3")
embeddings = embed([
"The quick brown fox jumps over the lazy dog."])    
init = tf.global_variables_initializer()

with tf.Session() as sess:
sess.run(init)
embeddings = sess.run(embeddings)
print(embeddings)

对于elmo等其他tf_hub模型,同样的代码结构也很好。

看起来要使用这个tensorflow集线器,我需要运行一个附加的初始值设定项:

init = tf.global_variables_initializer()
table_init = tf.tables_initializer()
with tf.Session() as sess:
sess.run([init, table_init])
embeddings_ = sess.run(embeddings)
print(embeddings)

您可以尝试

with tf.train.SingularMonitoredSession() as sess:
...

它自己完成所有标准初始化(包括"共享资源",我上次检查时没有公共的API(。

最新更新