Snurka Bill
Snurka Bill

Reputation: 983

Initializing variable with another variable using tensorflow

I am building neural network using denoising stacked autoencoders. I train autoencoder and then I would like to take the matrix of weights W and copy/initialize/clone it's values into new variable which is used in supervised optimization. How can I do such thing?

.initialized_value() doesn't work for me :/

Upvotes: 3

Views: 2353

Answers (1)

Yaroslav Bulatov
Yaroslav Bulatov

Reputation: 57983

Use var.assign, ie

vara = tf.Variable(0)
varb = tf.Variable(0)
init_op = tf.initialize_all_variables()
sess = tf.InteractiveSession()
sess.run([init_op])
sess.run([vara.assign_add(1)])
print 'variable a', vara.eval()
print 'variable b', varb.eval()
sess.run([varb.assign(vara)])
print 'variable b', varb.eval()

You should see

variable a 1
variable b 0
variable b 1

Upvotes: 3

Related Questions