datlife / yolov2

YOLOv2 Implementation in TF/Keras. Allowing to experiment on different feature detectors (MobileNet, Darknet-19). Paper: https://arxiv.org/abs/1612.08242
49 stars 13 forks source link

Probably a bug in loss function #4

Open nikitos9000 opened 6 years ago

nikitos9000 commented 6 years ago

Hi Dat,

It looks like there is a bug around the line https://github.com/dat-ai/yolov2/blob/master/models/YOLOv2.py#L346

I'm not 100% sure, but it looks like there's some value range mismatch:

At first, there's ground truth xy and wh. They both (true_box_xy and true_box_wh^2) have values relative to image shape (according to data_generator.py script), ranged from 0.0 to 1.0 true_box_xy = y_true[:, :, :, :, 0:2] true_box_wh = tf.sqrt(y_true[:, :, :, :, 2:4])

But then there's upper-left corner calculation which involves original true_box_xy minus half of true_box_wh^2 multiplied by output_size, which could be > 1.0 and seems incorrect. true_tem_wh = tf.pow(true_box_wh, 2) * output_size true_box_ul = true_box_xy - 0.5 * true_tem_wh

For pred_* variables the problem is the same.

As for me, the one solution is to not multiply wh by output size before corners calculation, another one is to make xy values relative to a cell.

BTW, it still trains somehow.

datlife commented 6 years ago

Hi @nsmetanin ,

Thank you for being interested in my work and pointing this bug. I will have to look into the code again since I have not actively worked on it for a while.

Best, Dat