Skip to content

Instantly share code, notes, and snippets.

@mortendahl
Last active May 2, 2019 09:38
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/6baa466228e754b79f8fa544c094966e to your computer and use it in GitHub Desktop.
Save mortendahl/6baa466228e754b79f8fa544c094966e to your computer and use it in GitHub Desktop.
import tensorflow as tf
import tf_encrypted as tfe
def provide_weights(): """Load model weight from disk using TensorFlow."""
def provide_input(): """Load and preprocess input data locally on the client."""
def receive_output(logits): return tf.print(tf.argmax(logits))
w0, b0, w1, b1, w2, b2 = provide_weights()
# run provide_input locally on the client and encrypt
x = tfe.define_private_input("prediction-client", provide_input)
# compute prediction on the encrypted input
layer0 = tfe.relu((tfe.matmul(x, w0) + b0))
layer1 = tfe.relu((tfe.matmul(layer0, w1) + b1))
logits = tfe.matmul(layer1, w2) + b2
# send result back to client, decrypt, and run receive_output locally
prediction_op = tfe.define_output("prediction-client", receive_output, logits)
with tfe.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