tensorflow如何在tensorflow外部复制变量并查看其值

时间:2019-10-14 22:53:24

标签: tensorflow variables

我有如下代码。它按预期工作。但是我想将变量embeddings的值保存在内存中。执行代码后,在我的embeddings中看不到变量variable explorer

我想避免将其写入磁盘。有没有简单的方法可以做到这一点?

import tensorflow_hub as hub
import tensorflow as tf

elmo = hub.Module("https://tfhub.dev/google/elmo/2", trainable=True)

x = ["she is the love of my life"]

# Extract ELMo features 
embeddings = elmo(x, signature="default", as_dict=True)["elmo"]

embeddings.shape


with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    sess.run(tf.tables_initializer())
    print (sess.run(embeddings))

0 个答案:

没有答案