Analysis on Position Errors of Object Detection Models and Solution

Symptom

During the model evaluation phase of object detection, false positive analysis and false negative analysis are important. In false positive analysis, the position error is mainly reflected by the probability of position false positive. In false negative analysis, the position error is mainly reflected by the probability of position false negative.

The model evaluation results in ModelArts are as follows:

Figure 1 Model evaluation results

The preceding figure shows an example of analysis on the object detection inference results. Graph a shows the analysis on the position false positive, class false positive, and background false positive. Graph b shows the analysis on the position false negative, class false negative, and background false negative.

In the preceding figure, position errors account for a large proportion of false positive and false negative errors. You are advised to refer to the following algorithms and technical description to understand how to reduce the position error probability and improve model inference accuracy.

Solution

  • GIoU loss

    The generalized IoU (GIoU) loss was first proposed by Stanford University. It overcomes the following disadvantages of the IoU loss:

    1. When predicted bounding box A and target bounding box B do not intersect, the IoU(A,B) is 0, which cannot accurately reflect the location and distance relationships between the two bounding boxes. In this case, the loss function cannot be derived. The IoU loss cannot be used for inference optimization where two bounding boxes do not intersect.
    2. Assume that the sizes of the predicted bounding box and the target bounding box are fixed. If the intersection area size of the two boxes is fixed (that is, the IoUs are the same), the IoUs cannot reflect how the two boxes intersect. The following figure shows three scenarios where the predicted bounding box and the target bounding box intersect. In the three scenarios, the IoUs are the same but the position relationships are greatly different.
    Figure 2 Position relationships between the predicted bounding box and the target bounding box when the IoUs are the same

    The following figure shows the formula for calculating the GIoU. In this formula, A indicates the predicted bounding box, B indicates the target bounding box, and C indicates the intersection area between A and B.

    Figure 3 GIoU calculation

    Formula for calculating the value of the GIoU loss:

  • DIoU loss

    Distance IoU (DIoU) incorporates the distance between the target bounding box and the anchor bounding box, overlapping rate, and scale. In this way, the target bounding box regression becomes more stable during object detection model training. It has the following advantages:

    1. A more direct regression minimizes a normalized distance between the anchor bounding box and the target bounding box, leading to much faster convergence.
    2. If bounding box regression is unavailable using the GIoU loss, for example, the target bounding box contains the predicted bounding box (see the following figure), the bounding boxes can be quickly regressed.
    Figure 4 The green bounding box indicates the target bounding box, and the red bounding box indicates the predicted bounding box.

    Formula for calculating DIoU:

    The letters in the formula are described as follows:

    The green bounding box indicates the predicted bounding box, and the black bounding box indicates the target bounding box. d indicates the Euclidean distance between the center points of the two boxes, and c indicates the length of the diagonal of the minimum intersection area.

    Formula for calculating the DIoU loss:

Verification

A dataset of traffic signal lights is used for verification. The dataset is used to detect traffic signal lights at the crossroads. There is only one class. The comparison between the false positive analysis before and after the DIoU loss is used shows that the DIoU loss significantly reduces the position false positive ratio.

Figure 5 Analysis and comparison of false positives after the DIoU loss is used

The comparison between the false negative analysis before and after the DIoU loss is used shows that the DIoU loss significantly reduces the position false negative ratio.

Figure 6 Analysis and comparison of false negatives after the DIoU loss is used

Suggestions

In the model inference result, if the position error ratio is large, you are advised to use the GIoU loss and DIoU loss for model optimization and enhancement during training.