Skip to content

Instantly share code, notes, and snippets.

@yinguobing
Last active April 3, 2019 11:40
Show Gist options
  • Save yinguobing/8fc7fd3ddbcc8db65cd9cf21cdab6ee7 to your computer and use it in GitHub Desktop.
Save yinguobing/8fc7fd3ddbcc8db65cd9cf21cdab6ee7 to your computer and use it in GitHub Desktop.
Load TensorFlow saved model and run inference.
import tensorflow as tf
MODEL_PATH = '/home/robin/Desktop/arc_inf/1554262166'
IMAGE_PATH = '/data/dataset/public/ms_celeb_1m/arc_face_data/img/0/0.jpg'
with tf.Session(graph=tf.Graph()) as sess:
# Restore model from the saved_modle file, that is exported by TensorFlow estimator.
tf.saved_model.loader.load(sess, ["serve"], MODEL_PATH)
# Get the output node from the graph.
graph = tf.get_default_graph()
output = graph.get_tensor_by_name('embeddings:0')
# Read in images to be processed. The image should be in size of 112x112x3.
with open(IMAGE_PATH, 'rb') as f:
_img_bytes = f.read()
# Run forward pass with images.
embd = sess.run(output, feed_dict={'input_tensor:0': [_img_bytes]})
# Print out the result.
print(embd[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment