sponge.metrics.MultiClassFocal
- class sponge.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.
Refer to Lin, Tsung-Yi, et al. 'Focal loss for dense object detection' .
- Parameters
num_class (int) – The class numbers.
beta (float, optional) – The moving average coefficient, default:
0.99
.gamma (float, optional) – The hyperparameters, default:
2.0
.e (float, optional) – The proportion of focal loss, default:
0.1
.neighbors (int, optional) – The neighbors to be mask in the target, default
2
.not_focal (bool, optional) – Whether focal loss, default:
False
.reducer_flag (bool, optional) – 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 sponge.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,)