Shortcuts

MaskedBalancedBCELoss

class mmocr.models.common.MaskedBalancedBCELoss(reduction='none', negative_ratio=3, fallback_negative_num=0, eps=1e-06)[source]

Masked Balanced BCE loss.

Parameters
  • reduction (str, optional) – The method to reduce the loss. Options are ‘none’, ‘mean’ and ‘sum’. Defaults to ‘none’.

  • negative_ratio (float or int) – Maximum ratio of negative samples to positive ones. Defaults to 3.

  • fallback_negative_num (int) – When the mask contains no positive samples, the number of negative samples to be sampled. Defaults to 0.

  • eps (float) – Eps to avoid zero-division error. Defaults to 1e-6.

Return type

None

forward(pred, gt, mask=None)[source]

Forward function.

Parameters
  • pred (torch.Tensor) – The prediction in any shape.

  • gt (torch.Tensor) – The learning target of the prediction in the same shape as pred.

  • mask (torch.Tensor, optional) – Binary mask in the same shape of pred, indicating positive regions to calculate the loss. Whole region will be taken into account if not provided. Defaults to None.

Returns

The loss value.

Return type

torch.Tensor

Read the Docs v: dev-1.x
Versions
latest
stable
v1.0.1
v1.0.0
0.x
v0.6.3
v0.6.2
v0.6.1
v0.6.0
v0.5.0
v0.4.1
v0.4.0
v0.3.0
v0.2.1
v0.2.0
v0.1.0
dev-1.x
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.