Skip to content

Instantly share code, notes, and snippets.

@jlebar
Created November 7, 2018 01:21
Show Gist options
  • Save jlebar/a0ff40f378f2fad99d059a2ab33e68da to your computer and use it in GitHub Desktop.
Save jlebar/a0ff40f378f2fad99d059a2ab33e68da to your computer and use it in GitHub Desktop.
Example of TF function with dynamic but nonetheless inferrable shapes
def model_fn_changing_shapes(x):
return 2 * x
def run_changing_shapes_model():
with tf.Session() as sess:
x = tf.placeholder(tf.float32, name='x')
result = xla.compile(model_fn_changing_shapes, (x,))[0]
a = sess.run(result, feed_dict={x: [1., 2.]})
b = sess.run(result, feed_dict={x: [1., 2., 3.]})
# Prints "a.shape = (2,); b.shape = (3,)"
print("a.shape = " + str(a.shape) + "; b.shape = " + str(b.shape))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment