I am trying to get a while loop working in TensorFlow, but am struggling to understand the body parameter of tf.while_loop.
In my code, I have a neural network defined as follows:
input_placeholder = tf.placeholder(dtype=np.float32, shape=[None, 2])
hidden_layer = tf.layers.dense(inputs=input_placeholder, units=10, activation=tf.nn.relu)
prediction_op = tf.layers.dense(inputs=hidden_layer, units=2)
I then want to run this prediction operation 10 times, feeding the prediction from one iteration as the input into the next iteration. My code for this is as follows:
num_steps = 10
condition = lambda step_num, input_placeholder: tf.less(step_num, num_steps)
_, final_prediction = tf.while_loop(condition, body, [step_num, latest_prediction])
What I am confused about is what to use for the body parameter. I need the body to take the prediction of the current iteration, and set this as the input for the next iteration.
Can I just use prediction_op for body? If so, how should I tell the while loop to update the value of input_placeholder after each call of prediction_op? Or should I do this a different way?
Thanks!