Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

sponge.metrics.BinaryFocal

View Source On Gitee
class sponge.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.

Refer to Lin, Tsung-Yi, et al. 'Focal loss for dense object detection' .

FL(pt)=αt(1pt)γlog(pt)
Parameters
  • alpha (float, optional) – The weight of cross entropy, default: 0.25.

  • gamma (float, optional) – The hyperparameters, modulating loss from hard to easy, default: 2.0.

  • feed_in (bool, optional) – Whether to convert prediction, default: False.

  • not_focal (bool, optional) – Whether focal loss, 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 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,)