Skip to content

Instantly share code, notes, and snippets.

@mortendahl
Last active April 29, 2019 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortendahl/a10de0d77eda607bb6ea4410f4b70d07 to your computer and use it in GitHub Desktop.
Save mortendahl/a10de0d77eda607bb6ea4410f4b70d07 to your computer and use it in GitHub Desktop.
import tensorflow as tf
def provide_weights():""" Load from disk """
def provide_input(): """ Pre-process """
def receive_output(logits): return tf.print(tf.argmax(logits))
# get model weights
w0, b0, w1, b1, w2, b2 = provide_weights()
# get prediction input
x = provide_input()
# compute prediction
layer0 = tf.nn.relu((tf.matmul(x, w0) + b0))
layer1 = tf.nn.relu((tf.matmul(layer0, w1) + b1))
logits = tf.matmul(layer2, w2) + b2
# process result of prediction
prediction_op = receive_output(logits)
# run graph execution in a tf.Session
with tf.Session() as sess:
sess.run(prediction_op)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment