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

about loss #7

Open
HonestyBrave opened this issue Aug 6, 2021 · 1 comment
Open

about loss #7

HonestyBrave opened this issue Aug 6, 2021 · 1 comment

Comments

@HonestyBrave
Copy link

hello, tztztztztz:
thankyou for your opensource code, it's very good!
but i have a question about loss, i read some blog about the loss, the yolov2 loss is like the picture, two red box in the picture is not find in your loss.py, is i didn't find or you do not write?

image

@tztztztztz
Copy link
Owner

Hi,

Thank you for using this repo!
In fact, the two losses in the red boxes ARE INCLUDED in the loss function.

yolov2.pytorch/loss.py

Lines 218 to 219 in 014559c

box_loss = 1 / b * cfg.coord_scale * F.mse_loss(delta_pred_batch * box_mask, box_target * box_mask, reduction='sum') / 2.0
iou_loss = 1 / b * F.mse_loss(conf_pred_batch * iou_mask, iou_target * iou_mask, reduction='sum') / 2.0

For box losses, the losses for both obj_coord and noobj_coord are included in a single tensor. Since the loss for noobj_coord is actually 0, I use a box_mask to mask out losses of noobj_coord.

For conf losses (iou_loss), the loss weights for conf_obj and conf_noobj are set by iou_mask

iou_mask = delta_pred_batch.new_ones((bsize, H * W, num_anchors, 1)) * cfg.noobject_scale

iou_mask[b, cell_idx, argmax_anchor_idx, :] = cfg.object_scale

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

2 participants