oneflow.nn.Threshold¶
-
class
oneflow.nn.
Threshold
(threshold: float, value: float)¶ The Threshold Activation. Return
x
ifx
is greater thanthreshold
, else returnvalue
.The interface is consistent with PyTorch. The documentation is referenced from https://pytorch.org/docs/1.10/generated/torch.nn.Threshold.html.
The formula is:
\[\begin{split}\text{Threshold}(x) = \begin{cases} x, & \text{ if } x > \text{ threshold } \\ \text{value }, & \text{ otherwise } \end{cases}\end{split}\]- Parameters
threshold (float) – The
threshold
value for the Threshold formulationvalue (float) – The
value
value for the Threshold formulation
- Shapes:
Input: \((N, *)\) where * means, any number of additional dimensions
Output: \((N, *)\), same shape as the input
- Returns
The result tensor
- Return type
Oneflow.Tensor
For example:
>>> import oneflow as flow >>> import numpy as np >>> x = np.array([-1, 0, 0.5, 1]).astype(np.float32) >>> input = flow.Tensor(x) >>> th = flow.nn.Threshold(threshold=0.5, value=0.2) >>> out = th(input) >>> out tensor([0.2000, 0.2000, 0.2000, 1.0000], dtype=oneflow.float32)