Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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