How to understand focal loss/GIOU (yolo improved loss function)

The formula of Focal Loss is as follows:

Focal Loss = -α(1 - p)^γ * log§

Among them, α is the adjustment factor for positive samples, γ is the parameter that controls the weight distribution of difficult and easy samples, and p is the probability value predicted by the model.

According to the formula, it can be seen that when the sample is a difficult sample, the value of (1 - p) is larger, so the weight of the loss will be increased. For easily classified samples, the value of (1 - p) is smaller, thereby reducing the weight of the loss.

for example

If we set γ=2, it means increasing the contribution of indistinguishable samples to the loss. Assume that the target categories are 1 (difficult samples) and category 2 (easy to classify samples), and assume that their prediction probabilities are 0.1 and 0.9 respectively. At this time, Focal Loss is calculated as follows:

For category 1 (difficult sample):
Focal Loss = -0.25 * (1 - 0.1)^2 * log(0.1) ≈ 0.798

For category 2 (easy to classify samples):
Focal Loss = -0.25 * (1 - 0.9)^2 * log(0.9) ≈ -0.097

It can be seen from the calculation results that for difficult samples (category 1), the value of Focal Loss is larger; while for easy-to-classify samples (category 2), the value of Focal Loss is smaller. This means that the model will pay more attention to the learning of difficult samples, thereby improving the classification ability of difficult-to-identify targets.

Therefore, Focal Loss does not mean that difficult-to-classify samples contribute more to the loss function, but balances the impact of difficult-to-class samples on loss by adjusting factors and parameters, thereby improving the performance of the model on category imbalance and difficult-to-use samples.

GIOU

GIOU (Generalized Intersection over Union) loss and IOU (Intersection over Union) loss are two common loss functions used in target detection. They differ in how they calculate the degree of overlap between target boxes.
Insert image description here

IOU Loss measures the degree of overlap between two target frames by calculating the ratio of their intersection area and union area. The formula is as follows:

IOU Loss = 1 - IOU

Among them, IOU represents the intersection and union ratio, and the calculation formula is:

IOU = Intersection / Union

GIOU Loss is improved on the basis of IOU Loss and solves the shortcomings of IOU Loss when dealing with highly inconsistent target boxes. GIOU Loss considers the bounding box of the target frame and the error relative to the bounding rectangle.

The formula of GIOU Loss is as follows:

GIOU Loss = 1 - GIOU

Among them, GIOU represents the generalized intersection and union ratio, and the calculation formula is:

GIOU = IOU - C(A, B) / Union

C(A, B) represents the squared difference of the diagonals of the circumscribed rectangles of target frames A and B.

for example:

Suppose we have two target boxes A and B, their coordinates are A(x1=10, y1=10, x2=60, y2=60) and B(x1=50, y1=50, x2=100, y2 =100). First, we calculate their IOU.

The intersection area of ​​A and B is (x1=50, y1=50, x2=60, y2=60), which is 100.
The union area of ​​A and B is (x1=10, y1=10, x2=100, y2=100), which is 8100.
The calculated IOU is 100 / 8100 ≈ 0.0123.

Next, we calculate GIOU.

The squared difference between the diagonals of the circumscribing rectangles of target boxes A and B is (60-10)^2 + (60-10)^2 + (100-50)^2 + (100-50)^2 = 6000. Calculate
GIOU For IOU - C(A, B) / Union = 0.0123 - 6000 / 8000 = -0.745

Therefore, the IOU Loss is 1 - 0.0123 ≈ 0.9877, and the GIOU Loss is 1 - (-0.745) ≈ 1.745. It can be seen that GIOU Loss considers the circumscribed rectangle of the target frame and gives a more accurate measure of overlap, which is more robust than IOU Loss.

Insert image description here

Guess you like

Origin blog.csdn.net/ALiLiLiYa/article/details/132752907
Recommended