4

当我遇到以下问题时,我正在尝试将 tf_hub 用于universal-sentence-encoder-large:

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)

其他 tf_hub 模型(如elmo.

4

2 回答 2

3

看起来要使用这个 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)
于 2018-11-10T15:55:54.713 回答
0

你可以试试

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

它自己进行所有标准初始化(包括“共享资源”,我上次检查时没有公共 API)。

于 2019-06-07T14:04:25.537 回答