mindscience.models.layers.InputScale
- class mindscience.models.layers.InputScale(input_scale, input_center=None)[源代码]
基于 \((x_i - input\_center)*input\_scale\) 将输入值缩放到指定区域。
- 参数:
input_scale (list) - 输入的缩放系数。
input_center (Union[list, None]) - 坐标平移的位置偏移。默认值:
None。
- 输入:
input (Tensor) - 形状为 \((*, channels)\) 的张量。
- 输出:
output (Tensor) - 形状为 \((*, channels)\) 的张量。
- 异常:
TypeError - 如果 input_scale 不是列表。
TypeError - 如果 input_center 不是列表或
None。
样例:
>>> import numpy as np >>> from mindscience.models.layers import InputScale >>> from mindspore import Tensor >>> inputs = np.random.uniform(size=(16, 3)) + 3.0 >>> inputs = Tensor(inputs.astype(np.float32)) >>> input_scale = [1.0, 2.0, 4.0] >>> input_center = [3.5, 3.5, 3.5] >>> net = InputScale(input_scale, input_center) >>> output = net(inputs).asnumpy() >>> assert np.all(output[:, 0] <= 0.5) and np.all(output[:, 0] >= -0.5) >>> assert np.all(output[:, 1] <= 1.0) and np.all(output[:, 1] >= -1.0) >>> assert np.all(output[:, 2] <= 2.0) and np.all(output[:, 2] >= -2.0)