mindspore.nn.Softmax2d

class mindspore.nn.Softmax2d[source]

Softmax function applied to 2D features data.

Applies Softmax to each location \((c, h, w)\) with an input Tensor of shape \((C, H, W)\) .

Inputs:
  • x (Tensor) - Tensor of shape \((N, C_{in}, H_{in}, W_{in})\) or \((C_{in}, H_{in}, W_{in})\). The input of Softmax with data type of float16 or float32.

Outputs:

Tensor, which has the same type and shape as x with values in the range[0,1].

Raises
  • TypeError – If dtype of x is neither float16 nor float32.

  • ValueError – If data_format is neither 'NCHW' nor 'CHW'.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, nn
>>> import numpy as np
>>> x = Tensor(np.array([[[[0.1, 0.2]], [[0.3, 0.4]], [[0.6, 0.5]]]]), mindspore.float32)
>>> softmax2d = nn.Softmax2d()
>>> output = softmax2d(x)
>>> print(output)
[[[[0.25838965 0.28001308]]
[[0.31559783 0.34200877]]
[[0.42601252 0.37797815]]]]