Generalized Focal Loss: Learning Qualified and Distributed Bounding Boxes for Dense Object Detection
- Publication
- NeurIPS 2020Conference
- First submitted to arXiv
- arXiv:2006.04388
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{objectdetectiongfl2020,
title = {{Generalized Focal Loss: Learning Qualified and Distributed Bounding Boxes for Dense Object Detection}},
author = {Xiang Li and Wenhai Wang and Lijun Wu and Shuo Chen and Xiaolin Hu and Jun Li and Jinhui Tang and Jian Yang},
year = {2020},
eprint = {2006.04388},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2006.04388}
}
This method has repeatedly appeared in recent object detection systems. Let’s take a quick look at its core concepts.
Problem Definition
In object detection, we are always chasing two types of scores:
- Classification Score: What is inside this box?
- Localization Quality: How accurate is this box?
Mainstream one-stage detectors (dense/one-stage) typically learn these two tasks separately: one branch for classification, another branch for quality (such as IoU or centerness).
When it comes to inference, all candidate boxes are sorted with NMS, and we directly multiply the two scores to get the final score, which determines which boxes survive as the final predictions.
Why multiply?
Intuitively, we want both the classification score and the localization score to be high.
Multiplication in the 0–1 score range rapidly pulls down the overall score if either side is low. Sounds reasonable, right?
But this brings two structural problems:
-
Inconsistency Between Training and Inference:
During training, the classification and quality branches are independent—the model is never explicitly required to make “the product of both” good. But in inference, we suddenly use their product for ranking. If the model could talk, it would probably complain: “Hey, that’s not what we agreed on!”
-
Interference from Negative Samples:
The quality branch is usually supervised only for positive samples; background or negative samples have no explicit constraints.
As a result, sometimes the quality score for background boxes can become inexplicably high:
- Even if the classification score is low, a sudden spike in the quality score may still make the final product rank high enough to push out true positives.
- In dense anchor/fully sampled scenarios, this kind of “mis-ranking” gets amplified, directly harming the final decision made by NMS.
These aren’t the only issues—we also have doubts about the representation of bounding boxes themselves.
For years, boxes have been treated as “deterministic coordinates,” but the real world is full of uncertainty: blurry boundaries, occlusion, annotator differences, etc. Describing everything with a single point is too rigid.
Some have introduced Gaussian distributions, letting the model learn a mean and variance to at least express “uncertainty.” But Gaussian distributions are inherently symmetric and unimodal; when faced with boundary predictions that may be skewed, long-tailed, or even multimodal, they can be too restrictive. A learned distribution here is a flexible box representation, not by itself a calibrated measure of annotator uncertainty.
So we’re stuck again:
- Score level: Classification and localization quality speak different languages; the training objective and inference ranking don’t match, and negative samples occasionally mess things up.
- Box representation: It’s either overly deterministic or oversimplified, making it hard to represent more flexible boundary predictions.
Can we make “classification” and “quality” speak the same language, aligning training and inference from the start?
Can we avoid presetting what the box distribution looks like, and instead let the model learn a “more general, more flexible” distributional representation directly?
Solution
Before diving into the methods proposed in this paper, let’s first review the Focal Loss we learned in the past.
Focal Loss
In one-stage object detection, the first challenge faced by the classifier is extreme sample imbalance.
Most candidate boxes are background (negative), while real foregrounds (positive) are extremely rare. This causes traditional cross-entropy loss to be dominated by “a huge number of easy background samples.” The model quickly learns to classify the background correctly, but struggles to properly learn those truly difficult foreground samples.
The goal of Focal Loss is:
Suppress the contribution of easy samples and highlight the impact of hard samples.
It introduces a “dynamic scaling factor” in front of the loss function. This makes the contribution of “samples that the model predicts with high confidence” close to zero, while “uncertain/easy-to-misclassify” samples are emphasized.
The formula is:
Where:
- : The model’s predicted probability for the positive class.
- : The ground truth label.
- : Controls the suppression strength for “easy samples.”
The key to this mechanism is its focusing idea: Focal Loss itself uses binary , and GFL extends that idea to continuous labels (). When we go beyond the simple “right/wrong” division and consider more fine-grained localization quality, the “hard example mining” spirit remains intact.
Quality Focal Loss
Having understood Focal Loss’s focusing mechanism, let’s take it a step further:
In object detection, outputting a box means not only answering “what class is this?” but also “how accurate is this box?”
Traditionally, classification scores and localization quality scores are learned separately and only multiplied at inference.
However, as we discussed, this “last-minute fusion” introduces inconsistency: the model is trained for classification, but inference relies on a combination of classification and quality, without real synergy.
To solve this, the authors propose Quality Focal Loss (QFL).
The design concept is: let the model learn the “classification × quality” composite score from the very beginning, rather than stitching them together afterward.
In practice, the authors first introduce continuous labels.
-
For an assigned positive sample's ground-truth class , the label is no longer simply or , but the current IoU between its predicted box and the assigned GT, i.e., . All other class components have target zero.
- : Not this class or quality is zero.
- : Perfect and high-quality match.
- In between: The box is partially correct, with limited quality.
-
For negative samples, all class labels remain (quality = 0).
-
The model output for each class is a sigmoid probability .
For the loss function, QFL achieves its goal in two steps:
It extends the original binary cross-entropy (BCE) into the full BCE form, and replaces the Focal modulation factor with a “continuous version based on label distance”:
Key points:
- When , reaches its global minimum.
- is the “continuous focusing factor”: the further the output deviates from the label, the heavier the penalty.
- If and an appropriate is chosen, this degenerates to the original Focal Loss form apart from the class-balancing factor omitted above.
With QFL, the model’s output already encodes both classification and quality signals, so during inference, sorting and NMS can directly use , greatly reducing inconsistencies.
Distribution Focal Loss
At this point, we’ve unified classification and quality in QFL.
Next, the remaining issue is box localization regression.
Traditionally, the offset for each edge (left, right, top, bottom) is regressed directly to a single number.
This is essentially telling the model:
“There’s only one correct answer—you must hit it exactly.”
This sounds reasonable, but it’s actually too strict.
Because in the real world, boundaries can be blurry or occluded, and annotations can differ. If you regress to a single value, it’s like asking an archer to “hit only the bullseye.” The training data here still provides one target box; the distribution is a more flexible prediction representation.
Some have thought of using a Gaussian distribution instead of a single point, allowing the model to express uncertainty. This is better than direct delta regression, but a Gaussian is symmetric and of fixed shape, and still cannot flexibly express things like “I lean more toward the left.”
The authors argue: Instead of forcing the model to “report an answer directly,” why not let the model “describe its own belief as a distribution”?
- First, discretize the possible regression range into bins ().
- Then, let the model output a softmax probability distribution over these bins.
- Finally, take the expected value of the distribution as the regression result:
This way, the model doesn’t have to represent its prediction with a single point, but can say “I think the answer is somewhere around here.”
However, this approach allows infinitely many distribution shapes to produce the same expected value, making efficient learning difficult.
So, the authors introduce a clever design: supervise only the two bins closest to the ground truth.
Suppose the true value is between and . Decompose it into weights:
- The closer to , the greater the weight for .
- The closer to , the greater the weight for .
Mathematically:
The loss function is simple—just use cross-entropy:
At the DFL optimum, and while the other bins approach zero, so the expected value reconstructs the target . An arbitrary prediction during training need not hit it exactly.
Generalized Focal Loss
If we plot the two lines (QFL and DFL) on the same coordinate system, we’ll see that we’ve been doing the same thing all along:
Between two adjacent label values, use probability to perform linear interpolation, and use “how close to the true value” to determine whether to amplify the penalty.
First, define the minimal local coordinate system:
-
Take two adjacent continuous label values .
-
The model only needs to predict their probabilities (with ).
-
The final continuous prediction is obtained by linear combination:
Next, embed the spirit of focusing on hard examples into the loss function in a continuous manner:
If is far from the ground truth :
- The penalty increases. If it’s close:
- The penalty decreases.
This leads us to Generalized Focal Loss (GFL):
This formula encapsulates two key elements:
- Soft-label cross-entropy (the term in brackets; weights determined by ’s relative position within );
- Continuous focusing factor (the greater the absolute distance, the stronger the penalty; controls the strength).
In this formula, the global minimum is reached when
At this point, , meaning the prediction exactly matches the continuous ground truth.
As increases, examples farther from the ground truth receive more weight relative to closer examples; with , it reduces to pure soft-label cross-entropy.
At this point, GFL gives us a clean perspective:
Describe continuous labels by “interpolation between two points,” and determine the focusing strength by “distance to the true value.”
Classification and quality finally speak the same language, and box localization evolves from a single point to a distribution;
Both can ultimately be understood through a single concise formula. In the detector, QFL and DFL are still applied separately, alongside the geometric box loss for assigned positives.
That’s the end of our look at this paper.
Congratulations.
Discussion
This paper conducts a comprehensive evaluation on COCO, following common settings:
- Training uses trainval35k (about 115K images).
- Validation uses minival (5K) for ablation studies.
- Final main results are reported on test-dev (20K).
The implementation is based on mmdetection default hyperparameters; unless otherwise stated, ablations use ResNet-50, 1× schedule (12 epochs), and no multi-scale training. The main test-dev comparison instead uses a 2× schedule (24 epochs) and multi-scale training. Speed is measured on RTX 2080Ti, batch=1 where available; different backbones and schedules cannot be treated as one controlled loss ablation.
Is QFL Effective?
Results are shown in the table above:
-
Table (a) Design Comparison: Unified Representation (QFL) Outperforms Separate or Implicit Schemes.
Under the same training settings and backbone, switching classification and localization quality to a single unified score (directly supervised by QFL) consistently surpasses:
- “Separate quality estimation” methods using IoU or centerness branches, and implicit weighting in classification loss.
In the matched rows, FCOS rises from 38.5 to 39.0 AP and ATSS from 39.2 to 39.9 AP when the centerness branch is replaced by QFL. This shows that using a single score to represent both “what” and “how well” performs better on overall AP in these tests; the separate IoU branch also exceeds the centerness branch on overall AP. There is a small exception: FCOS is 41.9 with QFL versus 42.0 with the separate IoU branch.
-
Table (b) Cross-architecture Generalization: Plug-and-Play, Consistent Gains.
Replacing the original classification objective in FoveaBox, RetinaNet and SSD512 with the joint representation and QFL raises overall AP 36.4→37.0, 35.6→36.4 and 29.4→30.2, respectively. These three tested designs benefit.
In practice, you can simply remove the “multiplication at inference” and use QFL’s output as the NMS ranking score.
-
Table (c) Parameter Sensitivity: is a Robust Choice.
QFL’s focusing factor uses ; in the tested ATSS settings, reaches the highest overall AP, 39.9 versus 37.6 at (table (c)). The table does not separately measure each hard and easy sample's contribution.
Is DFL Effective?
Results are shown in the table above:
-
Table (a) Advantages of Distributional Regression: General Distribution Outperforms Gaussian and Dirac.
Changing box regression from a single point (Dirac) to a general distribution with DFL raises FCOS overall AP 38.5→39.0 and ATSS 39.2→39.5. Their values rise 41.6→42.3 and 42.2→42.8. The general distribution without DFL reaches only 39.3 AP on ATSS, so representation and neighboring-bin supervision should be distinguished. ATSS slightly falls 57.4→57.3; not every column improves.
The paper's Figure 7 shows selected blurry-boundary and occlusion examples where the general distribution's predicted boxes are closer to the annotated boxes. The four directional distributions show where the model places probability mass.
-
Table (b) and (c) Hyperparameter Robustness: Is Insensitive, Smaller Is Better.
Figure 5(c) shows the regression-target histogram. In Table 2(b), or both reach 40.2 AP on ATSS with , while or reach 40.1. In Table 2(c), and both reach 40.2 AP at , with larger spacing slightly lower. The authors choose in practice.
-
Learning Efficiency: Pushing Probability Mass Toward the Ground Truth
DFL, through soft-label cross-entropy on two neighboring nodes, explicitly encourages probability to concentrate near , avoiding inefficient distributions with the same expectation but varying shapes. Table 2(a) reports higher overall AP and in the tested rows; it does not separately measure learning speed.
DFL upgrades box regression from “guessing a number” to “outputting a distribution whose expectation recovers the target at the optimum.” In these COCO experiments, overall box AP rises modestly. Table 3 reports the same 19.4 FPS before and after QFL/DFL on one RTX 2080Ti with batch size one; other hardware was not measured here.
Practical recommendations: , as default, and use with QFL/geometric losses.
For a controlled check of both losses together, Table 3's ATSS/ResNet-50 rows move from 39.2 AP at baseline to 39.9 with QFL, 39.5 with DFL, and 40.2 with both. All four rows report 19.4 FPS on the paper's RTX 2080Ti setup. The larger test-dev comparison in Table 4 instead uses 24 epochs and multi-scale training: GFL with ResNet-101 reaches 45.0 AP/14.6 FPS, while the ResNeXt-101-32×4d-DCN row reaches 48.2 AP/10.0 FPS. Those are different systems, so the difference from the 39.2-AP ablation is not the isolated effect of QFL and DFL.
Conclusion
GFL combines classification and localization quality into a single supervised score (QFL) and upgrades box regression from a single point to a learnable distribution (DFL).
The former addresses the long-standing inconsistency between training and inference; the latter enables the model to recover continuous target positions via expectation at its optimum, while representing a range of plausible boundary locations. This is not a calibrated measure of annotation uncertainty. Together, these designs form the Generalized Focal Loss framework, which pushed the accuracy-speed boundary of one-stage detectors further on COCO at the time.
GFL turns “score alignment” and “distributional regression” into reusable design languages:
- You can try QFL+DFL in a one-stage dense detector and test whether joint quality ranking and distributional geometry help under its own assignment and training setup;
- Or take them as conceptual sources for “quality as score” and “box as distribution,” to be compared alongside TAL, VFL, or even E2E alignment approaches.
It’s not the end, but it has changed the default mindset when designing detectors—a fact that remains clear in 2025.