mindsponge.metrics.BinaryFocal
- class mindsponge.metrics.BinaryFocal(alpha=0.25, gamma=2.0, feed_in=False, not_focal=False)[source]
Focal error for Binary classifications. Compute the binary classes focal error between prediction and the ground truth target.
\[\mathrm{FL}\left(p_{\mathrm{t}}\right)=-\alpha_{\mathrm{t}}\left(1-p_{\mathrm{t}}\right)^{\gamma} \log \left(p_{\mathrm{t}}\right)\]- Parameters
- 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 BinaryFocal >>> net = BinaryFocal() >>> 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,)