Yolov5: Objectness loss

Created on 23 Oct 2020  路  2Comments  路  Source: ultralytics/yolov5

鉂擰uestion

In the compute_loss() method, when calculating the objectness loss, only calculate the objectnessloss of the positive sample? Did the negative sample not participate in the calculation?

Additional context

tobj[b, a, gj, gi] = (1.0 - model.gr) + model.gr * iou.detach().clamp(0).type(tobj.dtype)
lobj += BCEobj(pi[..., 4], tobj) * balance[i] # obj loss

Stale question

Most helpful comment

I think that objetcness loss using all sample, not only positive sample.
The variable pi means all samples in a prediction layer.

Building the GT label corresponding to pi.

tobj = torch.zeros_like(pi[..., 0], device=device)  # target obj
tobj[b, a, gj, gi] = (1.0 - model.gr) + model.gr * iou.detach().clamp(0).type(tobj.dtype)  # iou ratio

Calculating loss

lobj += BCEobj(pi[..., 4], tobj) * balance[i]  # obj loss

All 2 comments

I think that objetcness loss using all sample, not only positive sample.
The variable pi means all samples in a prediction layer.

Building the GT label corresponding to pi.

tobj = torch.zeros_like(pi[..., 0], device=device)  # target obj
tobj[b, a, gj, gi] = (1.0 - model.gr) + model.gr * iou.detach().clamp(0).type(tobj.dtype)  # iou ratio

Calculating loss

lobj += BCEobj(pi[..., 4], tobj) * balance[i]  # obj loss

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lisa676 picture lisa676  路  3Comments

Single430 picture Single430  路  4Comments

Alex-afka picture Alex-afka  路  3Comments

xinxin342 picture xinxin342  路  3Comments

linhaoqi027 picture linhaoqi027  路  4Comments