Created
October 28, 2017 14:19
-
-
Save bzamecnik/59c3fb0068a92e6930baa12c6f9ca8b5 to your computer and use it in GitHub Desktop.
TensorFlow tf.Variable with dynamic shape
This file contains hidden or 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
# - prevent the variable to be used as a model parameter: trainable=False, collections=[] | |
# - allow dynamic variable shape (for the last batch): validate_shape=False | |
placeholder = tf.placeholder(dtype=tf.float32, shape=(None, 10)) | |
variable = tf.Variable(placeholder, trainable=False, collections=[], validate_shape=False) | |
with tf.Session() as sess: | |
sess.run(variable.initializer, feed_dict={placeholder: np.arange(20).reshape(2,10)}) | |
print('shape:', sess.run(tf.shape(variable))) | |
print(sess.run(variable)) | |
sess.run(variable.initializer, feed_dict={placeholder: np.arange(30).reshape(3,10)}) | |
print('shape:', sess.run(tf.shape(variable))) | |
print(sess.run(variable)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment