Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The 'bbox_iou' function on line 177 in 'yolov4.py' seems wrong #24

Closed
TCBocean opened this issue May 6, 2020 · 4 comments
Closed

The 'bbox_iou' function on line 177 in 'yolov4.py' seems wrong #24

TCBocean opened this issue May 6, 2020 · 4 comments

Comments

@TCBocean
Copy link

TCBocean commented May 6, 2020

left_up = tf.maximum(boxes1_coor[..., :2], boxes1_coor[..., :2])

The box1 and box1 of this line of code should not be able to get the coordinates of the upper left corner of the overlapping area.

@zxj11838
Copy link

zxj11838 commented Jun 5, 2020

I also found the same problem, this may be the reason why the network training loss is nan

@zxj11838 zxj11838 mentioned this issue Jun 5, 2020
@robisen1
Copy link

robisen1 commented Jun 5, 2020

I also found the same problem, this may be the reason why the network training loss is nan

do you have a solution to the issue?

@zxj11838
Copy link

zxj11838 commented Jun 8, 2020

I have changed,
left_up = tf.maximum(boxes1_coor[..., :2], boxes1_coor[..., :2])
to:
left_up = tf.maximum(boxes1_coor[..., :2], boxes2_coor[..., :2])

But the loss of training is still nan.

@rubencardenes
Copy link

Yes, that function is definitely wrong. I changed that line to compute left_up coordinates, as well as the right_down coordinates. I also found in some implementations the iou is computed using the maximum between the value and an epsilon as this:

def bbox_iou(boxes1, boxes2):

    boxes1_area = boxes1[..., 2] * boxes1[..., 3]
    boxes2_area = boxes2[..., 2] * boxes2[..., 3]

    boxes1_coor = tf.concat([boxes1[..., :2] - boxes1[..., 2:] * 0.5,
                             boxes1[..., :2] + boxes1[..., 2:] * 0.5], axis=-1)
    boxes2_coor = tf.concat([boxes2[..., :2] - boxes2[..., 2:] * 0.5,
                             boxes2[..., :2] + boxes2[..., 2:] * 0.5], axis=-1)

    left_up    = tf.maximum(boxes1_coor[..., :2], boxes2_coor[..., :2])
    right_down = tf.minimum(boxes1_coor[..., 2:], boxes2_coor[..., 2:])

    inter_section = tf.maximum(right_down - left_up, 0.0)
    inter_area = inter_section[..., 0] * inter_section[..., 1]
    union_area = boxes1_area + boxes2_area - inter_area
    iou       = tf.maximum(1.0 * inter_area / union_area, np.finfo(np.float32).eps)

    return iou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants