Loss Functions
Functions that measure the gap between predictions and targets: cross-entropy, focal loss, CTC, and more.
ArcFaceArcFace (Additive Angular Margin Loss) is a loss function that normalizes both the features and the weights of the last fully connected layer to unit length, adds a constant m to the angle θ between a feature and its target class, and computes the softmax loss on cos(θ + m). Because it leaves a fixed margin measured as arc length on the hypersphere, it pulls features of the same person together and pushes features of different people apart in face recognition.
Center LossCenter Loss is a loss function that learns a feature center for each class and pulls each sample's feature toward the center of its own class. Combined with the softmax loss, it keeps classes separated while compacting features within each class, producing discriminative features for tasks such as face recognition.
Contrastive LossContrastive Loss is a loss function for pairs of data points: it shrinks the output distance of similar pairs and pushes dissimilar pairs apart only when they are closer than a margin. From pairwise relations alone, it learns a low-dimensional embedding that also applies to new data.
CosFaceCosFace (Large Margin Cosine Loss) is a loss function that normalizes both the features and the weights of the last fully connected layer to unit length, subtracts a constant m from the cosine similarity of the target class, and then computes the softmax loss. Because it opens a margin directly on the cosine similarity used at test time, it produces features that make it easier to verify faces of people not seen in training.
Cross-EntropyCross-entropy is a loss function that measures how far the probability distribution output by a model is from the target distribution. It uses −log p as the loss, where p is the probability assigned to the correct class, and is the most widely used loss for training classifiers.
CTC LossCTC Loss is a loss function that trains without knowing how the outputs at each input time step (including blanks) align with the target string, by summing the probabilities of all paths that collapse to the target. It lets a network that outputs sequences be trained directly from pairs of unsegmented audio and transcriptions.
Dice LossDice loss is a loss function defined as 1 minus the Dice coefficient, which measures the overlap between the predicted region and the ground-truth region. Even in segmentation where the target occupies only a tiny part of the image, it learns the target without adjusting class weights.
Focal LossFocal Loss multiplies cross-entropy by a factor that shrinks the loss of examples the model already classifies correctly, focusing training on hard examples. In object detection, where background vastly outnumbers objects, it keeps class imbalance from stalling training.
Hinge LossThe hinge loss is a classification loss that is 0 when the score of the correct class wins by a margin of at least 1, and otherwise equals the shortfall. It is the foundation of support vector machine (SVM) training and concentrates learning on examples near the decision boundary.
Huber LossThe Huber loss is a loss function that behaves like the squared error while the error is small and grows with the same slope as the absolute error once the error exceeds a threshold δ. It keeps the smoothness of MSE while preventing outliers from dragging training off course.
InfoNCEInfoNCE is a loss function for representation learning: softmax cross-entropy that identifies the positive among candidates made up of one positive and several negatives. It was proposed in CPC, and minimizing it raises a lower bound on the mutual information between the context and the prediction target.
KL DivergenceThe KL divergence is a quantity that expresses how different two probability distributions are as a single non-negative number. It is used as a loss that pulls a model's distribution toward a target or teacher distribution, for example in knowledge distillation and VAEs.
Lovász-SoftmaxLovász-Softmax is a loss function that extends the IoU (Jaccard index) loss used to evaluate segmentation into a differentiable form via the Lovász extension, so that training minimizes it directly. Fine-tuning models trained with cross-entropy using it raised mIoU on PASCAL VOC and Cityscapes.
Mean Squared Error (MSE)Mean squared error (MSE) is a loss function that squares the difference between the prediction and the ground truth and averages it. It penalizes predictions that are far off heavily and is the most basic loss for training regression models that predict values.
NT-XentNT-Xent is a softmax cross-entropy using cosine similarity and a temperature that identifies two views made from the same image among the other views in the same mini-batch. Used in SimCLR, it pushes confusing negatives away more strongly.
PolyLossPolyLoss is a loss-function framework that rewrites cross-entropy and Focal Loss as sums of polynomials in (1 − p_t) and tunes their coefficients to the task. Its simplest form, Poly-1, just adds ε(1 − p_t) to cross-entropy, and it improved accuracy in image classification, object detection, and 3D detection.
SphereFace (A-Softmax)SphereFace (the A-Softmax loss) is a loss function that normalizes the weights of the last fully connected layer to unit length and multiplies the angle to the target class by m before computing the softmax loss. Features are arranged with an angular gap (margin) between classes, so even faces of people unseen in training can be matched by the angles of their features.
Supervised ContrastiveSupervised Contrastive (SupCon) is a loss function that uses labels to treat every example of the same class as a positive and examples of other classes as negatives, comparing them with a softmax to learn embeddings. It produces representations in which each class forms a cluster, and on ImageNet it matched or exceeded the accuracy of cross-entropy.
Triplet LossTriplet Loss is a loss function that learns embeddings so that data of the same kind as a reference example (the anchor) lies closer than data of a different kind, by at least a margin. Used for face recognition in FaceNet, it produces embeddings in which similarity can be judged by distance.
Tversky LossTversky loss is a loss function that uses the Tversky index, a generalization of the Dice coefficient, to give separate weights α and β to pixels wrongly predicted as foreground (FP) and pixels missed (FN). Increasing β penalizes misses more heavily, reducing missed detections in segmentation of small targets such as lesions.
