Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Tensorflow snippets
## Save tf model under graph-model
saver = tf.train.Saver() # general saver object
#saves a model every 2 hours and maximum 4 latest models are saved.
saver = tf.train.Saver(max_to_keep=4, keep_checkpoint_every_n_hours=2)
saver = tf.train.Saver([w1,w2]) # save a list of variables, 'my-test-model') /, 'my_test_model',global_step=1000), 'my-model', global_step=step,write_meta_graph=False) # dont save the model graph
## Recreate network
new_saver = tf.train.import_meta_graph('my_test_model-1000.meta')
with tf.Session() as sess:
new_saver.restore(sess, tf.train.latest_checkpoint('./'))
# Access the graph after loading the meta
graph = tf.get_default_graph()
# freeze gradient computation upto fc7
fc7 = tf.stop_gradient(fc7) # It's an identity function
# makes use of the Keras learning phase before tf-serving =>
from keras import backend as K
K.set_learning_phase(0) # all new operations will be in test mode from now on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment