Skip to content

Instantly share code, notes, and snippets.

@lmatt-bit
Created February 28, 2017 08:29
Show Gist options
  • Save lmatt-bit/080609129354d2181ae4d2a80b9fad33 to your computer and use it in GitHub Desktop.
Save lmatt-bit/080609129354d2181ae4d2a80b9fad33 to your computer and use it in GitHub Desktop.
tensorflow 0.12 save & load graph
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})
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