Updating unknown number of variables in TensorFlow
up vote
0
down vote
favorite
I have a collection of Variables in a TensorFlow graph which I want to update simultaneously all according to a similar rule. An example graph would be
a = tf.placeholder(tf.int32)
x1 = tf.Variable(0, tf.int32)
x2 = tf.Variable(1, tf.int32)
I want to then read in data to a
one value at a time, and at each step update x1
and x2
to max(current_value, a). This can be accomplished by adding two assign operations
u1 = x1.assign(tf.maximum(a, x1))
u2 = x2.assign(tf.maximum(a, x2))
and if the input data is in a list data
, and the collection of variables vars
, this can be accomplished by the loop (apologies for the ugly logic!)
with tf.Session() as sess:
for d in data:
if vars = :
continue
if vars = ['x1']:
sess.run(u1, a:d)
if vars = ['x2']:
sess.run(u2, a:d)
if vars = ['x1', 'x2']:
sess.run([u1, u2], a:d)
However, if I have a large number of xi
and want to avoid repetitive code
building by hand each of the updating ui
, is there a way to build a function which takes as arguments a list of variables and generates new assignment variables just for them?
python tensorflow
add a comment |
up vote
0
down vote
favorite
I have a collection of Variables in a TensorFlow graph which I want to update simultaneously all according to a similar rule. An example graph would be
a = tf.placeholder(tf.int32)
x1 = tf.Variable(0, tf.int32)
x2 = tf.Variable(1, tf.int32)
I want to then read in data to a
one value at a time, and at each step update x1
and x2
to max(current_value, a). This can be accomplished by adding two assign operations
u1 = x1.assign(tf.maximum(a, x1))
u2 = x2.assign(tf.maximum(a, x2))
and if the input data is in a list data
, and the collection of variables vars
, this can be accomplished by the loop (apologies for the ugly logic!)
with tf.Session() as sess:
for d in data:
if vars = :
continue
if vars = ['x1']:
sess.run(u1, a:d)
if vars = ['x2']:
sess.run(u2, a:d)
if vars = ['x1', 'x2']:
sess.run([u1, u2], a:d)
However, if I have a large number of xi
and want to avoid repetitive code
building by hand each of the updating ui
, is there a way to build a function which takes as arguments a list of variables and generates new assignment variables just for them?
python tensorflow
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a collection of Variables in a TensorFlow graph which I want to update simultaneously all according to a similar rule. An example graph would be
a = tf.placeholder(tf.int32)
x1 = tf.Variable(0, tf.int32)
x2 = tf.Variable(1, tf.int32)
I want to then read in data to a
one value at a time, and at each step update x1
and x2
to max(current_value, a). This can be accomplished by adding two assign operations
u1 = x1.assign(tf.maximum(a, x1))
u2 = x2.assign(tf.maximum(a, x2))
and if the input data is in a list data
, and the collection of variables vars
, this can be accomplished by the loop (apologies for the ugly logic!)
with tf.Session() as sess:
for d in data:
if vars = :
continue
if vars = ['x1']:
sess.run(u1, a:d)
if vars = ['x2']:
sess.run(u2, a:d)
if vars = ['x1', 'x2']:
sess.run([u1, u2], a:d)
However, if I have a large number of xi
and want to avoid repetitive code
building by hand each of the updating ui
, is there a way to build a function which takes as arguments a list of variables and generates new assignment variables just for them?
python tensorflow
I have a collection of Variables in a TensorFlow graph which I want to update simultaneously all according to a similar rule. An example graph would be
a = tf.placeholder(tf.int32)
x1 = tf.Variable(0, tf.int32)
x2 = tf.Variable(1, tf.int32)
I want to then read in data to a
one value at a time, and at each step update x1
and x2
to max(current_value, a). This can be accomplished by adding two assign operations
u1 = x1.assign(tf.maximum(a, x1))
u2 = x2.assign(tf.maximum(a, x2))
and if the input data is in a list data
, and the collection of variables vars
, this can be accomplished by the loop (apologies for the ugly logic!)
with tf.Session() as sess:
for d in data:
if vars = :
continue
if vars = ['x1']:
sess.run(u1, a:d)
if vars = ['x2']:
sess.run(u2, a:d)
if vars = ['x1', 'x2']:
sess.run([u1, u2], a:d)
However, if I have a large number of xi
and want to avoid repetitive code
building by hand each of the updating ui
, is there a way to build a function which takes as arguments a list of variables and generates new assignment variables just for them?
python tensorflow
python tensorflow
asked Nov 9 at 20:32
Joseph Gallagher
12
12
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232892%2fupdating-unknown-number-of-variables-in-tensorflow%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown