Created
February 28, 2017 08:29
-
-
Save lmatt-bit/080609129354d2181ae4d2a80b9fad33 to your computer and use it in GitHub Desktop.
tensorflow 0.12 save & load graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
import os | |
with tf.Session() as sess: | |
md = "./models/" | |
fgn = "model.ckpt" | |
fgp = os.path.join(md, fgn) | |
saver = tf.train.import_meta_graph(fgp + ".meta") | |
saver.restore(sess, fgp) | |
print sess.run('c:0') | |
print sess.run('b:0') | |
print sess.run('a:0') | |
print sess.run('c:0', feed_dict = {'a:0': 10.0}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
import os | |
with tf.Session() as sess: | |
a = tf.Variable(5.0, name='a') | |
b = tf.Variable(6.0, name='b') | |
c = tf.multiply(a, b, name="c") | |
sess.run(tf.global_variables_initializer()) | |
print a | |
print b | |
print c | |
#print a.eval() # 5.0 | |
#print b.eval() # 6.0 | |
#print c.eval() # 30.0 | |
#ogn = "graph.pb" | |
#md = "./models/" | |
#tf.train.write_graph(sess.graph_def, md, ogn, as_text=False) | |
md = "./models/" | |
fgn = "model.ckpt" | |
saver = tf.train.Saver() | |
saver.save(sess, os.path.join(md, fgn), meta_graph_suffix='meta', write_meta_graph=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment