PSENetLoss<T>

Models & Types · AiDotNet.Document.OCR.TextDetection

PSENet’s training objective (Wang et al. 2019, Eq. 5): L = lambda L_c + (1 - lambda) L_s with lambda = 0.7, both terms Dice losses over the sigmoid of the kernel logits.

Inheritance: LossFunctionBase<T> → PSENetLoss<T>

How It Works

Layout is [batch, kernels, H, W] (or [kernels, H, W]), kernels ordered smallest to largest, so the LAST channel is the complete text map S_n. Dice is the paper’s D(S, G) = 2 sum(S G) / (sum S^2 + sum G^2), with the reference implementation’s 0.001 added to each denominator term, computed per image and per kernel.

L_c uses Online Hard Example Mining on the complete map: every positive pixel plus the 3x as many highest-scoring negatives. L_s scores the shrunk kernels only where the predicted complete map says text (S_n > 0.5), so they are not penalised outside a text region. The masks are constants; gradient flows through the scores alone, as in the reference.

Constructors

Constructor Summary
PSENetLoss()

Methods

Method Summary
T CalculateLoss(Vector<T> predicted, Vector<T> actual)
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target)

Fields

Field Summary
double CompleteMapWeight Weight of the complete-text-map term (the paper’s lambda).
int NegativeRatio Hard negatives kept per positive by OHEM.