Search code examples
object-detectionloss-functiondarknetyolov4

What's the complete loss function used by yolov4?


I am unable to find the explanation for the loss function of yolov4.


Solution

  • First, to understand the YOLOv4 loss, I think you should read about the original YOLO loss that was released in YOLO first paper (https://arxiv.org/abs/1506.02640), you can find it here.
    In YOLOv4, you will have the exact same ideas, but with:

    • Binary cross entropy for the objectness and classification scores,
    • Box-per-cell level prediction instead of cell level prediction for the class probabilities, so a slightly different penalization for the classification terms,
    • CIoU Loss instead of MSE for the regression terms (x,y,w,h). CIoU stands for Complete Intersection over Union, and is not so far from the MSE loss. It proposes to compare width and height a bit more interestingly (consistency between aspect ratios), but it keeps the MSE for the comparison between bounding box centers. You can find more details in this paper.

    Finally, YOLOv4 loss can be written this way. With the complete CIoU loss terms, it looks like this.