clip_sigmoid.py 498 Bytes
Newer Older
raojy's avatar
raojy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Copyright (c) OpenMMLab. All rights reserved.
import torch
from torch import Tensor


def clip_sigmoid(x: Tensor, eps: float = 1e-4) -> Tensor:
    """Sigmoid function for input feature.

    Args:
        x (Tensor): Input feature map with the shape of [B, N, H, W].
        eps (float): Lower bound of the range to be clamped to.
            Defaults to 1e-4.

    Returns:
        Tensor: Feature map after sigmoid.
    """
    y = torch.clamp(x.sigmoid_(), min=eps, max=1 - eps)
    return y