阅读完文档后,我保存了一个模型TensorFlow,这是我的演示代码:
# Create some variables.
v1 = tf.Variable(..., name="v1")
v2 = tf.Variable(..., name="v2")
...
# Add an op to initialize the variables.
init_op = tf.global_variables_initializer()
# Add ops to save and restore all the variables.
saver = tf.train.Saver()
# Later, launch the model, initialize the variables, do some work, save the
# variables to disk.
with tf.Session() as sess:
sess.run(init_op)
# Do some work with the model.
..
# Save the variables to disk.
save_path = …Run Code Online (Sandbox Code Playgroud) 我尝试简单地保存和恢复图形,但最简单的示例不能按预期工作(这是使用版本0.9.0或0.10.0在Linux 64上使用python 2.7或3.5.2在没有CUDA的情况下完成的)
首先我保存图形如下:
import tensorflow as tf
v1 = tf.placeholder('float32')
v2 = tf.placeholder('float32')
v3 = tf.mul(v1,v2)
c1 = tf.constant(22.0)
v4 = tf.add(v3,c1)
sess = tf.Session()
result = sess.run(v4,feed_dict={v1:12.0, v2:3.3})
g1 = tf.train.export_meta_graph("file")
## alternately I also tried:
## g1 = tf.train.export_meta_graph("file",collection_list=["v4"])
Run Code Online (Sandbox Code Playgroud)
这将创建一个非空的文件"文件",并将g1设置为看起来像正确的图形定义的东西.
然后我尝试恢复此图:
import tensorflow as tf
g=tf.train.import_meta_graph("file")
Run Code Online (Sandbox Code Playgroud)
这没有错误,但根本不返回任何内容.
任何人都可以提供必要的代码,只需保存"v4"的图形并完全恢复它,以便在新的会话中运行它会产生相同的结果吗?