# Scale¶

Computes a per-element affine transformation: $$output = (\text{input} \cdot \text{scale} + \text{shift})^{\text{power}}$$ on an input tensor into an output tensor.

## Attributes¶

mode Scale coefficients can be applied across: - UNIFORM Identical coefficients for all elements. - CHANNEL Identical coefficients for all elements in the same channel. - ELEMENTWISE Identical coefficients for all elements with the same channel and spatial coordinates.

scale the scale coefficient to use. If empty, defaults to 1.

shift the shift coefficient to use. If empty, defaults to 0.

power the power coefficient to use. If empty, defaults to 1.

channel_axis the channel axis to use. In cases where CHANNEL transformation is used, for input $$[a_0,..,a_{\text{channel_axis}},..,a_n]$$ the coefficients are addressed at $$[a_{\text{channel_axis}}]$$. In cases where ELEMENTWISE transformation is used, for input $$[a_0,..,a_{\text{channel_axis}},..,a_n]$$ the coefficients are addressed at $$[a_{\text{channel_axis}},..,a_n]$$.

## Inputs¶

input: tensor of type T.

## Outputs¶

output: tensor of type T.

## Data Types¶

T: int8, float16, float32, bfloat16

## Shape Information¶

input and output are tensors with a shape of $$[a_0,...,a_n], n \geq 4$$

## DLA Support¶

DLA FP16 and DLA INT8 are supported. Custom values for the power coefficient are not supported.

## Examples¶

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)
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]]],
]
]
)