def gwd_loss(self, pred, target, fun='log', tau=1.0, alpha=1.0, normalize=False):
    (xy_p, R_p, S_p) = self.xywhr2xyrs(pred)
    (xy_t, R_t, S_t) = self.xywhr2xyrs(target)
    xy_distance = (xy_p - xy_t).square().sum(axis=(- 1))
    Sigma_p = R_p.matmul(S_p.square()).matmul(R_p.transpose([0, 2, 1]))
    Sigma_t = R_t.matmul(S_t.square()).matmul(R_t.transpose([0, 2, 1]))
    whr_distance = paddle.diagonal(S_p, axis1=(- 2), axis2=(- 1)).square().sum(axis=(- 1))
    whr_distance = (whr_distance + paddle.diagonal(S_t, axis1=(- 2), axis2=(- 1)).square().sum(axis=(- 1)))
    _t = Sigma_p.matmul(Sigma_t)
    _t_tr = paddle.diagonal(_t, axis1=(- 2), axis2=(- 1)).sum(axis=(- 1))
    _t_det_sqrt = paddle.diagonal(S_p, axis1=(- 2), axis2=(- 1)).prod(axis=(- 1))
    _t_det_sqrt = (_t_det_sqrt * paddle.diagonal(S_t, axis1=(- 2), axis2=(- 1)).prod(axis=(- 1)))
    whr_distance = (whr_distance + ((- 2) * (_t_tr + (2 * _t_det_sqrt)).clip(0).sqrt()))
    distance = (xy_distance + ((alpha * alpha) * whr_distance)).clip(0)
    if normalize:
        wh_p = pred[..., 2:4].clip(min=1e-07, max=10000000.0)
        wh_t = target[..., 2:4].clip(min=1e-07, max=10000000.0)
        scale = ((wh_p.log() + wh_t.log()).sum(dim=(- 1)) / 4).exp()
        distance = (distance / scale)
    if (fun == 'log'):
        distance = paddle.log1p(distance)
    if (tau >= 1.0):
        return (1 - (1 / (tau + distance)))
    return distance
def gwd_loss(self, pred, target, fun='log', tau=1.0, alpha=1.0, normalize=False):
    (xy_p, R_p, S_p) = self.xywhr2xyrs(pred)
    (xy_t, R_t, S_t) = self.xywhr2xyrs(target)
    xy_distance = (xy_p - xy_t).square().sum(axis=(- 1))
    Sigma_p = R_p.matmul(S_p.square()).matmul(R_p.transpose([0, 2, 1]))
    Sigma_t = R_t.matmul(S_t.square()).matmul(R_t.transpose([0, 2, 1]))
    whr_distance = paddle.diagonal(S_p, axis1=(- 2), axis2=(- 1)).square().sum(axis=(- 1))
    whr_distance = (whr_distance + paddle.diagonal(S_t, axis1=(- 2), axis2=(- 1)).square().sum(axis=(- 1)))
    _t = Sigma_p.matmul(Sigma_t)
    _t_tr = paddle.diagonal(_t, axis1=(- 2), axis2=(- 1)).sum(axis=(- 1))
    _t_det_sqrt = paddle.diagonal(S_p, axis1=(- 2), axis2=(- 1)).prod(axis=(- 1))
    _t_det_sqrt = (_t_det_sqrt * paddle.diagonal(S_t, axis1=(- 2), axis2=(- 1)).prod(axis=(- 1)))
    whr_distance = (whr_distance + ((- 2) * (_t_tr + (2 * _t_det_sqrt)).clip(0).sqrt()))
    distance = (xy_distance + ((alpha * alpha) * whr_distance)).clip(0)
    if normalize:
        wh_p = pred[..., 2:4].clip(min=1e-07, max=10000000.0)
        wh_t = target[..., 2:4].clip(min=1e-07, max=10000000.0)
        scale = ((wh_p.log() + wh_t.log()).sum(dim=(- 1)) / 4).exp()
        distance = (distance / scale)
    if (fun == 'log'):
        distance = paddle.log1p(distance)
    if (tau >= 1.0):
        return (1 - (1 / (tau + distance)))
    return distance