def smooth_l1(x): l2 = 0.5 * (x**2.0) l1 = tf.abs(x) - 0.5 condition = tf.less(tf.abs(x), 1.0) re = tf.where(condition, l2, l1) return re