pypto.relu#
产品支持情况#
产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
Atlas A3 训练系列产品/Atlas A3 推理系列产品 |
√ |
Atlas A2 训练系列产品/Atlas A2 推理系列产品 |
√ |
功能说明#
对 input 的每个元素进行整流线性单元(Rectified Linear Unit)运算,即只保留正数部分,负数变为0。计算公式如下:
\[
res_i = \max(0, input_i)
\]
函数原型#
relu(input: Tensor) -> Tensor
参数说明#
参数名 |
输入/输出 |
说明 |
|---|---|---|
input |
输入 |
源操作数。 |
返回值说明#
返回输出Tensor,Tensor的数据类型和Shape与input相同。
约束说明#
input 不支持 nan、inf 等特殊值。
调用示例#
TileShape设置示例#
说明:调用该operation接口前,应通过set_vec_tile_shapes设置TileShape。
TileShape维度应和输出一致。
示例1:输入input shape为[m, n],输出为[m, n], TileShape设置为[m1, n1], 则m1, n1分别用于切分m, n轴。
pypto.set_vec_tile_shapes(4, 16)
接口调用示例#
input_tensor = pypto.tensor([-2.0, 0.0, 3.0], pypto.DT_FP32)
out = pypto.relu(input_tensor)
结果示例如下:
输入数据input: [[-2.0 0.0 3.0]]
输出数据out: [[ 0.0 0.0 3.0]]