SSD Series 3 - Loss Calculation

SSD series:
SSD series 1 - network structure
SSD series 2 - PriorBox
SSD series 3 - loss calculation

1. Determine positive and negative sample labels

  The first step in loss calculation is to assign positive and negative sample labels to all PriorBoxes and determine the corresponding real object labels.

  During the generation process of the PriorBox of SSD, a total of 8732 PriorBox coordinates and corresponding category and position prediction values ​​are generated. Next, each PriorBox needs to be labeled, and qualified positive samples and negative samples are screened out. The basis is to judge by the IoU value between the predicted value and the true value:

  • When judging positive and negative samples, the IoU threshold is set to 0.5, that is, when the maximum IoU between a PriorBox and all real boxes is less than 0.5, the box is judged as a negative sample.
  • When judging the corresponding relationship, the PriorBox and its real frame with the largest IoU are used as its position coordinates.
  • The PriorBox with the largest IoU with the real box, even if the IoU is not the largest IoU between this PriorBox and all real box IoUs, the Box must be mapped to the real box to ensure the recall of the real box.
  • When predicting the position of the border, SSD is the same as Faster RCNN, which is the offset of the prediction relative to the prediction frame. Therefore, after obtaining the corresponding relationship, the offset needs to be calculated. For the formula, refer to Faster RCNN Series 2——Overview of the true value and predicted value of RPN

2. Calculation of positioning loss

  After the first step is completed, there are positive and negative samples and the real frame corresponding to each sample. At this time, the positioning loss calculation can be performed. SSD uses smooth L 1 0 smooth_{L1}0smoothL 1The 0 function is used as a positioning loss function, and it is only calculated for positive samples. For formula reference:Faster RCNN Series 3——Detailed explanation of the true value of RPN and calculation of loss value

3. Difficult sample mining

  After completing the first step, since the number of objects in an image is not too large, there will be a large number of negative samples. If the loss calculation is performed at this time, the positive samples will play little role.

  SSD achieves sample balance by ensuring the ratio of positive and negative samples. The specific method is to calculate the loss of all negative samples and sort them, select a part with a larger loss value for backpropagation, and discard the remaining negative samples. The number of negative samples is three times that of positive samples.

4. Category loss calculation

  SSD uses cross-entropy loss to calculate category loss, and all positive and negative samples participate in the calculation. For the formula, refer to Faster RCNN Series 3——Real Value Detailed Explanation and Loss Value Calculation of RPN

Guess you like

Origin blog.csdn.net/python_plus/article/details/130603969