ncdl.nn.Hardsigmoid

class ncdl.nn.Hardsigmoid(*args: Any, **kwargs: Any)

Applies the Hardsigmoid function element-wise.

Hardsigmoid is defined as:

\[\begin{split}\text{Hardsigmoid}(x) = \begin{cases} 0 & \text{if~} x \le -3, \\ 1 & \text{if~} x \ge +3, \\ x / 6 + 1 / 2 & \text{otherwise} \end{cases}\end{split}\]
Parameters:

inplace – can optionally do the operation in-place. Default: False

Shape:
  • Input: \((*)\), where \(*\) means any number of dimensions.

  • Output: \((*)\), same shape as the input.

scripts/activation_images/Hardsigmoid.png

Examples:

>>> m = nn.Hardsigmoid()
>>> input = torch.randn(2)
>>> output = m(input)
__init__(inplace: bool = False) None

Methods

__init__([inplace])

forward(input)

Attributes

inplace