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?
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
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.
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.
Calculating loss