kuangliu / pytorch-retinanet

RetinaNet in PyTorch
992 stars 250 forks source link

Background should have been considered in the loss function. #76

Closed zjysteven closed 4 years ago

zjysteven commented 4 years ago

First I want to thank the author for this implementation. I find the overall codes are clear and easy to follow than many others.

However, after checking across several others' implementations, e.g., https://github.com/NVIDIA/retinanet-examples/blob/5663247b88a19fcdee78ae5ae9fba5b4a88de029/retinanet/model.py#L156-L158 https://github.com/fizyr/keras-retinanet/blob/a8bbd6535655602a84f194b1557be1ed5180fa71/keras_retinanet/losses.py#L47-L50

I think that the background should have been considered when calculating the focal loss. In fact, it is exactly the great number of anchors assigned with the background (which are negative samples) that motivates the design of focal loss. Therefore, the below implementation is not correct. https://github.com/kuangliu/pytorch-retinanet/blob/2d7c663350f330a34771a8fa6a4f37a2baa52a1d/loss.py#L29-L31

Please correct me if I'm wrong or miss anything.

zjysteven commented 4 years ago

Please ignore my last comment. The above implementation is correct and indeed calculates background anchors' loss.