| Files | Last commit | Last update |
|---|---|---|
| 15 days ago | ||
| 22 days ago | ||
| 22 days ago | ||
| 22 days ago | ||
| 22 days ago | ||
| 1 month ago | ||
| 22 days ago | ||
| 18 days ago |
Relu6D
English | 简体中文
Applicable Products
| Product | Support |
|---|---|
| Ascend 950PR&950DT products | √ |
| Atlas A3 products | √ |
| Atlas A2 products | √ |
| Atlas 200I/500 A2 inference products | √ |
| Atlas inference products | √ |
| Atlas training products | √ |
Function
- Operator function: Relu6D is the ReLU6 activation function with a scaling coefficient. It elementwise truncates the input tensor from below first (negative values become 0) and then truncates it from above (limits it to
6*scale). Whenscale ≥ 0, the output value range is[0, 6*scale]; whenscale < 0, the output always equals6*scale. Whenscale = 1.0(the default), it is equivalent to standard ReLU6. It suits activation layers of lightweight vision networks such as the MobileNet series, limiting the activation value range and improving numerical stability in low-precision quantization scenarios. - Formula:
Relu6D(x)=min(max(x, 0), 6⋅scale)Relu6D(x) = \min(\max(x,\ 0),\ 6 \cdot scale)
In the formula, xx is the input tensor, scalescale is the threshold scaling coefficient (default 1.01.0), and yy is the output tensor. When scale ≥ 0, the value range is [0, 6⋅scale][0,\ 6 \cdot scale]; when scale < 0, the output is always 6⋅scale6 \cdot scale.
Parameters
| Parameter name | Input/Output/Attribute | Description | Data type | Data format |
|---|---|---|---|---|
| x | Input | The input feature tensor, corresponding to x in the formula. | FLOAT16, FLOAT, INT32, BFLOAT16 | ND |
| y | Output | The output tensor, corresponding to y in the formula, with the same shape and dtype as input x. | FLOAT16, FLOAT, INT32, BFLOAT16 | ND |
| scale | Optional attribute | The threshold scaling coefficient, corresponding to scale in the formula; the upper threshold = 6*scale. Default value: 1.0 (corresponding to standard ReLU6). | FLOAT | - |
Constraints
- The shapes of input x and output y must be the same.
- Up to 8-dimensional tensors are supported.
- Dynamic shapes and dynamic ranks are supported.
- Empty tensors return successfully directly: tiling sets
blockNumto 0 and allocates no data processing resources, and both Kernel Init and Process return early without initiating GM reads or writes. - Invalid range of the total element count: the total number of flattened elements of
x(the shape product) overflows int64. - scale constraints: the upper threshold is
6*scale. Whenscale = 0, the upper threshold is 0 and the output is always 0. Whenscale < 0, the upper threshold6*scale < 0and the output always equals6*scale(both are mathematically valid boundary semantics). For int32, the threshold is truncated toward zero. Invalid ranges:scaleis NaN/±Inf, or for int326*scaleexceeds[-2147483648, 2147483648).
Invocation Description
| Invocation method | Sample code | Description |
|---|---|---|
| GE graph mode | test_geir_relu6_d.cpp | Calls the Relu6D operator by building the graph through the operator IR. |
Compile and run the sample (execute in the repository root directory):
bash build.sh --run_example relu6_d graph