Scale¶
计算每个元素的仿射变换: \(output = (\text{input} \cdot \text{scale} + \text{shift})^{\text{power}}\),将输入张量转换为输出张量。
属性¶
mode 缩放系数可以应用于: - UNIFORM 所有元素使用相同的系数。 - CHANNEL 同一通道中的所有元素使用相同的系数。 - ELEMENTWISE 具有相同通道和空间坐标的所有元素使用相同的系数。
scale 要使用的缩放系数。如果为空,则默认为 1。
shift 要使用的偏移系数。如果为空,则默认为 0。
power 要使用的幂系数。如果为空,则默认为 1。
channel_axis 要使用的通道轴。在使用 CHANNEL 变换的情况下,对于输入 \([a_0,..,a_{\text{channel_axis}},..,a_n]\),系数在 \([a_{\text{channel_axis}}]\) 处寻址。在使用 ELEMENTWISE 变换的情况下,对于输入 \([a_0,..,a_{\text{channel_axis}},..,a_n]\),系数在 \([a_{\text{channel_axis}},..,a_n]\) 处寻址。
输入¶
input: 类型为 T 的张量。
输出¶
output: 类型为 T 的张量。
数据类型¶
T: int8, float16, float32, bfloat16
形状信息¶
input 和 output 是形状为 \([a_0,...,a_n], n \geq 4\) 的张量
DLA 支持¶
支持 DLA FP16 和 DLA INT8。不支持 power 系数的自定义值。
示例¶
Scale 4D
in1 = network.add_input("input1", dtype=trt.float32, shape=(1, 1, 3, 3))
scale_u = np.array([2], np.float32).reshape(-1)
shift_u = np.array([1], np.float32).reshape(-1)
power_u = np.array([2], np.float32).reshape(-1)
layer = network.add_scale(in1, trt.ScaleMode.UNIFORM, shift=shift_u, scale=scale_u, power=power_u)
network.mark_output(layer.get_output(0))
inputs[in1.name] = np.array(
[
[
[
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0],
]
]
]
)
outputs[layer.get_output(0).name] = layer.get_output(0).shape
expected[layer.get_output(0).name] = np.array([[[[9.0, 25.0, 49.0], [81.0, 121.0, 169.0], [225.0, 289.0, 361.0]]]])
Scale 5D
in1 = network.add_input("input1", dtype=trt.float32, shape=(1, 2, 1, 3, 3))
scale_u = np.array([1, 2], np.float32).reshape(-1)
shift_u = np.array([0, 1], np.float32).reshape(-1)
power_u = np.array([1, 2], np.float32).reshape(-1)
layer = network.add_scale_nd(
in1, trt.ScaleMode.CHANNEL, shift=shift_u, scale=scale_u, power=power_u, channel_axis=1
)
network.mark_output(layer.get_output(0))
inputs[in1.name] = np.array(
[
[
[
[
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0],
]
],
[
[
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0],
]
],
]
]
)
outputs[layer.get_output(0).name] = layer.get_output(0).shape
expected[layer.get_output(0).name] = np.array(
[
[
[
[
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0],
]
],
[[[9.0, 25.0, 49.0], [81.0, 121.0, 169.0], [225.0, 289.0, 361.0]]],
]
]
)
C++ API¶
有关 C++ IScaleLayer 算子的更多信息,请参阅 C++ IScaleLayer 文档。
Python API¶
有关 Python IScaleLayer 算子的更多信息,请参阅 Python IScaleLayer 文档。