clip_sigmoid.py 498 Bytes
Newer Older
dingchang's avatar
dingchang committed
1
# Copyright (c) OpenMMLab. All rights reserved.
2
import torch
3
from torch import Tensor
4
5


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

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

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