Created
November 7, 2018 01:21
-
-
Save jlebar/a0ff40f378f2fad99d059a2ab33e68da to your computer and use it in GitHub Desktop.
Example of TF function with dynamic but nonetheless inferrable shapes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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