【问题标题】:Problems with tensorflow hub: Table not initializedtensorflow hub的问题:表未初始化
【发布时间】:2019-06-07 22:04:25
【问题描述】:

当我遇到以下问题时,我正在尝试将 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

【问题讨论】:

    标签: tensorflow tensorflow-hub


    【解决方案1】:

    看起来要使用这个 tensorflow hub,我需要运行一个额外的初始化程序:

    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)
    

    【讨论】:

    • 不知道为什么,但这对我没有帮助。仍然在生产中引发错误。
    【解决方案2】:

    你可以试试

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

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

    【讨论】:

      猜你喜欢
      • 2011-04-29
      • 2018-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      • 1970-01-01
      • 2016-06-30
      相关资源
      最近更新 更多