I use the follow code to calculate pow:
eq2 = tf.pow(cos_t, FLAGS.margin-2*p, name='calc_cos_mt_eq2')
The TensorFlow generated graph like this: tf.pow genreate Log op in gradient caculate
When I changed the code to the following:
eq2 = tf.multiply(cos_t, FLAGS.margin-2*p, name='calc_cos_mt_eq2')
tf.multiply generate no log op The Log op disappear. If the input value is less than 0, the Log op will generate lots of nan. Does is a bug in tensorflow or something I make wrong?
The function of this code is:
def calc_cos_mt(self, cos_t):
'''calculate cos(m*theta)
'''
cos_mt = 0.0
sin2_t = 1 - cos_t * cos_t
flag = -1.0
for p in range(FLAGS.margin // 2 + 1):
flag *= -1.0
eq1 = tf.multiply(flag, self.c_map[2*p], name='calc_cos_mt_eq1')
# eq2 = tf.pow(cos_t, FLAGS.margin-2*p, name='calc_cos_mt_eq2')
eq2 = tf.multiply(cos_t, FLAGS.margin-2*p, name='calc_cos_mt_eq2')
eq3 = tf.pow(sin2_t, p, name='calc_cos_mt_eq3')
cos_mt = tf.add(cos_mt, tf.multiply(tf.multiply(eq1, eq2), eq3, name='calc_cos_mt_eq'), name='cos_mt_add')
return cos_mt