1

Given that I have some input batch x with shape (batch_size, n_features) how would I use tf.get_variable(...) to create another matrix with shape (batch_size) if it isn't known ahead of time.

For example I am able to do:

b = tf.zeros(shape = (tf.shape(x)[0]))

But I am unable to do:

b = tf.get_variable("b", shape = (tf.shape(x)[0]), initializer = tf.constant_initializer(0.0))

6
  • You have a typo right there, after shape= there should be a parenthesis opening, in both code snippets Commented May 25, 2017 at 5:56
  • oops fixed it!! Commented May 25, 2017 at 5:58
  • How does batch size affects one of your Variable ? It is common that they donnot interact. Commented May 25, 2017 at 7:14
  • When you need to create the hidden state for an RNN don't you need to know how many samples are in the batch? Commented May 25, 2017 at 9:16
  • if the problem is solved due to a simple typo, just remove the question Commented May 25, 2017 at 19:51

1 Answer 1

1

You can use tf.Variable(dims=[tf.shape(x)[0]], validate_shape=False) to set a dynamic shape for batch size.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.