mindflow.cell.InputScale

View Source On Gitee
class mindflow.cell.InputScale(input_scale, input_center=None)[source]

Scale the input value to specified region based on \((x_i - input\_center)*input\_scale\)

Parameters
  • input_scale (list) – The scale factor of input.

  • input_center (Union[list, None]) – Position offset of coordinate translation. Default: None.

Inputs:
  • input (Tensor) - Tensor of shape \((*, channels)\).

Outputs:

Tensor of shape \((*, channels)\).

Raises
  • TypeError – If input_scale is not a list.

  • TypeError – If input_center is not a list or None.

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> from mindflow.cell 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[:, 0] >= -1.0)
>>> assert np.all(output[:, 2] <= 2.0) and np.all(output[:, 0] >= -2.0)