mindspore.nn.MultiClassDiceLoss¶
-
class
mindspore.nn.
MultiClassDiceLoss
(weights=None, ignore_indiex=None, activation="softmax")[source]¶ When there are multiple classifications, label is transformed into multiple binary classifications by one hot. For each channel section in the channel, it can be regarded as a binary classification problem, so it can be obtained through the binary loss of each category, and then the average value.
- Parameters
weights (Union[Tensor, None]) – Tensor of shape [num_classes, dim]. The weight shape[0] should be equal to y shape[1].
activation (Union[str, Cell]) – Activate function applied to the output of the fully connected layer, eg. ‘ReLU’. Default: ‘softmax’. Choose from: [‘softmax’, ‘logsoftmax’, ‘relu’, ‘relu6’, ‘tanh’,’Sigmoid’]
- Inputs:
y_pred (Tensor) - Tensor of shape (N, C, …). The y_pred dimension should be greater than 1. The data type must be float16 or float32.
y (Tensor) - Tensor of shape (N, C, …). The y dimension should be greater than 1. The data type must be loat16 or float32.
- Outputs:
Tensor, a tensor of shape with the per-example sampled MultiClass Dice Losses.
- Raises
ValueError – If the shapes are different.
TypeError – If the type of inputs are not Tensor.
ValueError – If the dimension of y or y_pred is less than 2.
ValueError – If the weight shape[0] is not equal to y.shape[1].
ValueError – If weight is a tensor, but the dimension is not 2.
- Supported Platforms:
Ascend
GPU
Examples
>>> loss = nn.MultiClassDiceLoss(weights=None, ignore_indiex=None, activation="softmax") >>> y_pred = Tensor(np.array([[0.2, 0.5], [0.3, 0.1], [0.9, 0.6]]), mstype.float32) >>> y = Tensor(np.array([[0, 1], [1, 0], [0, 1]]), mstype.float32) >>> output = loss(y_pred, y) >>> print(output) 0.3283009