mindsponge.metrics.MultiClassFocal

class mindsponge.metrics.MultiClassFocal(num_class, beta=0.99, gamma=2.0, e=0.1, neighbors=2, not_focal=False, reducer_flag=False)[source]

Focal error for multi-class classifications. Compute the multiple classes focal error between prediction and the ground truth target. Reference: Lin, Tsung-Yi, et al. ‘Focal loss for dense object detection’ .

Parameters
  • num_class (int) – The class numbers.

  • beta (float) – The moving average coefficient, default: 0.99.

  • gamma (float) – The hyperparameters, default: 2.0.

  • e (float) – The proportion of focal loss, default: 0.1.

  • neighbors (int) – The neighbors to be mask in the target, default 2.

  • not_focal (bool) – Whether focal loss, default: “False”.

  • reducer_flag (bool) – Whether to aggregate the label values of multiple devices, default: “False”.

Inputs:
  • prediction (Tensor) - Predict values, shape is \((batch\_size, ndim)\).

  • target (Tensor) - Label values, shape is \((batch\_size, ndim)\).

Outputs:

Tensor, shape is \((batch\_size,)\).

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor
>>> from mindsponge.metrics import MultiClassFocal
>>> net = MultiClassFocal(10)
>>> prediction = Tensor(np.random.randn(32, 10).astype(np.float32))
>>> target = Tensor(np.random.randn(32, 10).astype(np.float32))
>>> out = net(prediction, target)
>>> print(out.shape)
(32,)