Created
September 11, 2017 20:29
-
-
Save ikhlestov/46fecf638be11679c901e1a6b9abea7b to your computer and use it in GitHub Desktop.
pytorch: tensorflow while loop
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
import tensorflow as tf | |
first_counter = tf.constant(0) | |
second_counter = tf.constant(10) | |
some_value = tf.Variable(15) | |
# condition should handle all args: | |
def cond(first_counter, second_counter, *args): | |
return first_counter < second_counter | |
def body(first_counter, second_counter, some_value): | |
first_counter = tf.add(first_counter, 2) | |
second_counter = tf.add(second_counter, 1) | |
return first_counter, second_counter, some_value | |
c1, c2, val = tf.while_loop( | |
cond, body, [first_counter, second_counter, some_value]) | |
with tf.Session() as sess: | |
sess.run(tf.global_variables_initializer()) | |
counter_1_res, counter_2_res = sess.run([c1, c2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment