mmdetection icon indicating copy to clipboard operation
mmdetection copied to clipboard

Suspicious implementation of multi-class version _focal_loss_cost

Open tjyuyao opened this issue 1 year ago • 4 comments

https://github.com/open-mmlab/mmdetection/blob/f78af7785ada87f1ced75a2313746e4ba3149760/mmdet/models/task_modules/assigners/match_cost.py#L252C1-L269C38

When the input is not binary, why in line 262 sigmoid is used instead of softmax? In the sigmoid case, the score is not normalized among classes IMO. Further, after the line 268, only the score of the correct class is selected to for training, and why minus neg_cost (which I view as a repeatition of positive pos_cost, according to the analysis of monoticity)?. This implementation is not correct IMO. Please also refer to this link https://zhuanlan.zhihu.com/p/308290543 .

Please let me know if I missed something. Thank you very much!

tjyuyao avatar Sep 05 '23 04:09 tjyuyao

@tjyuyao The reason is that focal loss does not actually support softmax mode.

hhaAndroid avatar Sep 05 '23 05:09 hhaAndroid

@hhaAndroid I read the focal loss paper which says it should be naturally extended to multi-class version, and the zhihu link seems to provide a correct implementation, which is very similar to the implementation here if sigmoid is changed to softmax. Without softmax, the score of the negative classes can not be trained to decrease which I think is quite different from the idea of cross entropy.

I try to search your answer "The reason is that focal loss does not actually support softmax mode." and fail to find any references. Would you kindly explain why not the case?

tjyuyao avatar Sep 05 '23 05:09 tjyuyao

@jshilong May I have your suggestions on this issue? I have read #4559 and it would be very nice to have opinions from someone familiar with these lines of code. Thanks in advance!

tjyuyao avatar Sep 05 '23 06:09 tjyuyao

@hhaAndroid @tjyuyao I had the same question. Is it solved now?

Wolfybox avatar Apr 08 '24 06:04 Wolfybox