I was trying to use tf.cond() to create 2 different graphs based on a condition. On, both the graphs we want to have weight regularization loss and thus we use tf.losses.get_regularization_loss(). Here is a pseudo code of our project
def net_1(x,y):
statement 1 (has trainable params)
statement 2 (has trainable params)
return
def net_2(x,y):
statement 1 (has trainable params)
statement 2 (has trainable params)
statement 3 (has trainable params)
return
step = tf.get_or_create_global_step()
tf.cond(tf.greater(step, 100), net_1, net_2)
loss = 0.0
loss += tf.losses.get_regularization_loss()
If we keep the tf.losses.get_regularization_loss() we get the error:
Retval[0] does not have value
Otherwise, there is no error.
Is there any special care to be taken with tf.cond() if we want to impose tf.losses.get_regularization_loss().