Skip to content

Instantly share code, notes, and snippets.

@Breta01
Last active March 6, 2018 21:14
Show Gist options
  • Save Breta01/c8b2df2b05b3ec54f1aa95e7a03a2907 to your computer and use it in GitHub Desktop.
Save Breta01/c8b2df2b05b3ec54f1aa95e7a03a2907 to your computer and use it in GitHub Desktop.
Importing and using TensorFlow graph (model)
sess = tf.Session()
# Import graph from the path and recover session
saver = tf.train.import_meta_graph('models/model_name.meta', clear_devices=True)
saver.restore(sess, 'models/model_name')
# There are TWO options how to access the operation (choose one)
# FROM SAVED COLLECTION:
activation = tf.get_collection('activation')[0]
# BY NAME:
activation = tf.get_default_graph.get_operation_by_name('activation_opt').outputs[0]
# Use imported graph for data
# You have to feed data as {'x:0': data}
# Don't forget on ':0' part!
data = 50
result = sess.run(activation, {'x:0': data})
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment