Skip to content

Instantly share code, notes, and snippets.

@amogh112
Created April 24, 2018 02:55
Show Gist options
  • Save amogh112/c80778819703c59608254255cb16fa8e to your computer and use it in GitHub Desktop.
Save amogh112/c80778819703c59608254255cb16fa8e to your computer and use it in GitHub Desktop.
import tensorflow as tf
def load_graph(frozen_graph_filename):
# We load the protobuf file from the disk and parse it to retrieve the
# unserialized graph_def
with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
# Then, we import the graph_def into a new Graph and returns it
with tf.Graph().as_default() as graph:
# The name var will prefix every op/nodes in your graph
# Since we load everything in a new graph, this is not needed
tf.import_graph_def(graph_def, name="prefix")
return graph
graph=load_graph('bcdf_emotions.pb')
for op in graph.get_operations():
print(op.name)
x = graph.get_tensor_by_name('prefix/dense_4_input:0')
y = graph.get_tensor_by_name('prefix/output_node0:0')
i=np.random.rand(136)
with tf.Session(graph=graph) as sess:
y_out=sess.run(y,feed_dict={x:[i]})
print(y_out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment