Skip to content

Instantly share code, notes, and snippets.

@miquelbeltran
Last active August 31, 2018 08:24
Show Gist options
  • Select an option

  • Save miquelbeltran/b73f88f620ffe6e7e7ae743b96e4298e to your computer and use it in GitHub Desktop.

Select an option

Save miquelbeltran/b73f88f620ffe6e7e7ae743b96e4298e to your computer and use it in GitHub Desktop.
import tensorflow as tf
inp = tf.placeholder(name="inp", dtype=tf.float32, shape=(1, 1))
w = tf.Variable(tf.zeros([1, 1], tf.float32), dtype=tf.float32, name="w")
y = tf.matmul(w, inp)
out = tf.identity(y, name="out")
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
# After Init var, change the value to 2
assignment = w.assign([[2]])
sess.run(assignment)
output = sess.run(out, feed_dict={inp: [[1]]})
print(output)
frozen_graph = freeze_session(sess, output_names=[out.op.name])
tflite_model = tf.contrib.lite.toco_convert(frozen_graph, [inp], [out])
open("mat_mul.tflite", "wb").write(tflite_model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment