def smoothL1(x, sigma):
'''
Tensorflow implementation of smooth L1 loss defined in Fast RCNN:
(https://arxiv.org/pdf/1504.08083v2.pdf)
0.5 * (sigma * x)^2 if |x| < 1/sigma^2
smoothL1(x) = {
|x| - 0.5/sigma^2 otherwise
'''
with tf.variable_scope('smoothL1'):
conditional = tf.less(tf.abs(x), 1/sigma**2)
close = 0.5 * (sigma * x)**2
far = tf.abs(x) - 0.5/sigma**2
return tf.where(conditional, close, far)
评论列表
文章目录