2

I'm trying to initialize a tf.Variable from a tensor object. Normally, from another tf.Variable you simply just used the initialized_value() but if you make a tensor object this does not work:

a = tf.constant([4,5,6])
b = tf.Variable(a.initialized_value())

I have tried b = tf.Variable(a) but upon initialize_all_variables() being ran, tensorflow asks for a placeholder to be filled which is not correct.

The reason why I'm doing this in the first place is that @mrry has suggested to place a tf.Variable into the params argument in tf.gather to help speed things up.

Thanks for your feedback!

1 Answer 1

2

This seems to work

a = tf.constant([4,5,6])
b = tf.Variable(a)
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())
print b.eval()
Sign up to request clarification or add additional context in comments.

1 Comment

I ended up just using tf.assign after reading your suggestion. I think there was something wrong with how I was initializing the variables. Thanks!

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.