Skip to content

Probably a bug in loss function #4

@nikita-smetanin

Description

@nikita-smetanin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions