mindspore.ops.BiasAdd

class mindspore.ops.BiasAdd(*args, **kwargs)[source]

Returns sum of input and bias tensor.

Adds the 1-D bias tensor to the input tensor, and broadcasts the shape on all axis except for the channel axis.

Parameters

data_format (str) – The format of input and output data. It should be ‘NHWC’, ‘NCHW’ or ‘NCDHW’, default is ‘NCHW’.

Inputs:
  • input_x (Tensor) - The input tensor. The shape can be 2-5 dimensions.

  • bias (Tensor) - The bias tensor, with shape \((C)\). The shape of bias must be the same as input_x’s channel dimension.

Outputs:

Tensor, with the same shape and type as input_x.

Raises

TypeError – If data_format, input_x or bias is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> input_x = Tensor(np.arange(6).reshape((2, 3)), mindspore.float32)
>>> bias = Tensor(np.random.random(3).reshape((3,)), mindspore.float32)
>>> bias_add = ops.BiasAdd()
>>> output = bias_add(input_x, bias)
>>> print(output.shape)
(2, 3)