YOLOv3_TensorFlow icon indicating copy to clipboard operation
YOLOv3_TensorFlow copied to clipboard

focal loss 和论文不同??

Open nobody-cheng opened this issue 5 years ago • 8 comments

您好: focal_mask = alpha * tf.pow(tf.abs(object_mask - tf.sigmoid(pred_conf_logits)), gamma) 1*(label - logits)^2 是不是少计算了一个取对数log? 8904720-ff70ec8fe128e133

nobody-cheng avatar Aug 06 '19 02:08 nobody-cheng

On the original paper, it was mentioned it did not help, it seems Yolo is not sensible to unbalanced classes.

fariquelme avatar Aug 06 '19 22:08 fariquelme

@nobody-cheng No, it's consistent with the original paper. Note that the formula you cited is a mask array. The log part is in the conf_loss part and conf_loss *= focal_mask. I didn't include the alpha in my implementation. To be exactly the same with the paper, the codes need to be:

alpha_weight = tf.where(tf.equal(object_mask, 1), alpha, 1 - alpha)
focal_weight = tf.pow(object_mask - tf.nn.sigmoid(pred_conf_logits), gamma)
focal_mask = alpha_weight * focal_weight
conf_loss = conf_loss * focal_mask

wizyoung avatar Aug 09 '19 15:08 wizyoung

@fariquelme I don't think YOLO is not sensible to unbalanced classes. Otherwise the author would not design the ignore_mask in the loss function. I've said that in readme file "These are all good strategies but it does not mean they will definitely improve the performance". To make focal loss really work, alpha_weight and gamma needs to be tuned(see my comments above). In my own experiments (on my private dataset), focal loss is useful.

wizyoung avatar Aug 09 '19 15:08 wizyoung

Nice, maybe they implemented it wrong ? they explicitly say it dropped their mAP by 2 points. Btw, thanks for your implementation, it helped me a lot!

fariquelme avatar Aug 09 '19 15:08 fariquelme

@fariquelme Yes, I guess the author implemented it wrong or did not tune to a better parameter. In my experiments, alpha is more important than gamma and alpha needs to be carefully tuned. (The current version does not include the alpha parameter and I will update my repo tomorrow). Actually many people found that focal loss did help in their experiments. Check https://www.zhihu.com/question/293369755/answer/488355189 (In Chinese. You can google translate it)

wizyoung avatar Aug 09 '19 16:08 wizyoung

Are you going to implement the focal loss in this repository?? It would help me a lot 😅

mcartagenah avatar Aug 18 '19 03:08 mcartagenah

Focal loss is already in the code. Specifically, the log part has been implemented beforehand in line 282 and 283 of model.py.

bitgs avatar Oct 23 '19 04:10 bitgs

I want to use yolov3 to predict the number of real-time person from the rtsp stream with suited interval,anyone has the right python file?

bujianyiwang avatar Jan 16 '20 06:01 bujianyiwang