caro.mss
caro.mss

Reputation: 169

YOLOv8 dfl_loss metric

I was wondering how to interpret different losses in the YOLOv8 model. I've easily found explanations about the box_loss and the cls_loss. About the dfl_loss I don't find any information on the Internet. I've also checked the YOLOv8 Docs.

I've found an article about the Dual Focal loss but not sure it corresponds to the YOLOv8 dfl_loss : Dual Focal Loss to address class imbalance in semantic segmentation

Could someone explain to me what is the dfl_loss and how to analyse it ? Thanks !

Upvotes: 16

Views: 26648

Answers (3)

thomas
thomas

Reputation: 1

https://ieeexplore.ieee.org/document/9792391

 @staticmethod
    def _df_loss(pred_dist, target):
        """Return sum of left and right DFL losses."""
        # Distribution Focal Loss (DFL) proposed in Generalized Focal Loss https://ieeexplore.ieee.org/document/9792391
        tl = target.long()  # target left
        tr = tl + 1  # target right
        wl = tr - target  # weight left
        wr = 1 - wl  # weight right
        return (F.cross_entropy(pred_dist, tl.view(-1), reduction='none').view(tl.shape) * wl +
                F.cross_entropy(pred_dist, tr.view(-1), reduction='none').view(tl.shape) * wr).mean(-1, keepdim=True)

Upvotes: 0

SOU
SOU

Reputation: 51

DFL stands for Distribution Focal Loss. Class imbalance is not relevant. It is used for bounding box regression along with CIOU. Although I haven't fully grasped the paper yet, it seems that the calculations also take into account the vicinity of the ground truth because the ground truth for the boxes is not always completely trustworthy. To understand this, I believe studying anchor-free detection is also necessary.

https://github.com/implus/GFocal

Upvotes: 5

Mohit Gupta
Mohit Gupta

Reputation: 107

There is an explanation on Matlab page: https://www.mathworks.com/matlabcentral/fileexchange/104395-dual-focal-loss-dfl?s_tid=FX_rc2_behav

Broadly speaking, DFL loss 'considers' the problem of class imbalance while training a NN. Class imbalance occurs when there is one class which occurs too frequently and another which occurs less. For ex: In street imagery say 100 photos, one can have 200 cars and only 10 bicycles. One wants to detect both cars and bikes. This is case of class imbalance, when you train a NN, since there are lot of cars, NN will learn to accurately localize cars whereas, bikes are too less so, it might not learn to localize it properly. With dfl loss, every time the NN tries to classify bike there is increased loss. So, now NN puts more importance on less frequent classes. This explanation is on a very general level. To know more, refer the paper on Focal loss and then on DFL.

Upvotes: 9

Related Questions