def smooth_l1_loss(bbox_prediction, bbox_target, sigma=1.0):
"""
Return Smooth L1 Loss for bounding box prediction.
Args:
bbox_prediction: shape (1, H, W, num_anchors * 4)
bbox_target: shape (1, H, W, num_anchors * 4)
Smooth L1 loss is defined as:
0.5 * x^2 if |x| < d
abs(x) - 0.5 if |x| >= d
Where d = 1 and x = prediction - target
"""
sigma2 = sigma ** 2
diff = bbox_prediction - bbox_target
abs_diff = tf.abs(diff)
abs_diff_lt_sigma2 = tf.less(abs_diff, 1.0 / sigma2)
bbox_loss = tf.reduce_sum(
tf.where(
abs_diff_lt_sigma2, 0.5 * tf.square(abs_diff),
abs_diff - 0.5
), [1]
)
return bbox_loss
评论列表
文章目录