class_docstr: Implements the loss as the sum of the followings:
  1. Confidence Loss: All labels, with hard negative mining
  2. Localization Loss: Only on positive labels
  Suppose input dboxes has the shape 8732x4
class_docstr_tok: ["Implements","the","loss","as","the","sum","of","the","followings",":","1",".","Confidence","Loss",":","All","labels",",","with","hard","negative","mining","2",".","Localization","Loss",":","Only","on","positive","labels","Suppose","input","dboxes","has","the","shape","8732x4"]
docstr: ploc, plabel: Nx4x8732, Nxlabel_numx8732
      predicted location and labels
  
  gloc, glabel: Nx4x8732, Nx8732
      ground truth location and labels
docstr_tok: ["ploc",",","plabel",":","Nx4x8732",",","Nxlabel_numx8732","predicted","location","and","labels","gloc",",","glabel",":","Nx4x8732",",","Nx8732","ground","truth","location","and","labels"]
code: def forward(self, ploc, plabel, gloc, glabel):
      """
      ploc, plabel: Nx4x8732, Nxlabel_numx8732
          predicted location and labels
  
      gloc, glabel: Nx4x8732, Nx8732
          ground truth location and labels
      """
      mask = glabel > 0
      pos_num = mask.sum(dim=1)
  
      vec_gd = self._loc_vec(gloc)
  
      # sum on four coordinates, and mask
      sl1 = self.sl1_loss(ploc, vec_gd).sum(dim=1)
      sl1 = (mask.float() * sl1).sum(dim=1)
  
      # hard negative mining
      con = self.con_loss(plabel, glabel)
  
      # postive mask will never selected
      con_neg = con.clone()
      con_neg[mask] = 0
      _, con_idx = con_neg.sort(dim=1, descending=True)
      _, con_rank = con_idx.sort(dim=1)
  
      # number of negative three times positive
      neg_num = torch.clamp(3 * pos_num, max=mask.size(1)).unsqueeze(-1)
      neg_mask = con_rank < neg_num
  
      # print(con.shape, mask.shape, neg_mask.shape)
      closs = (con * (mask.float() + neg_mask.float())).sum(dim=1)
  
      # avoid no object detected
      total_loss = sl1 + closs
      num_mask = (pos_num > 0).float()
      pos_num = pos_num.float().clamp(min=1e-6)
      ret = (total_loss * num_mask / pos_num).mean(dim=0)
      return ret
  
imports: import torch
  import torch.nn
  from torchvision.models.resnet import resnet18, resnet34, resnet50, resnet101, resnet152
  from torch.nn.parallel import DistributedDataParallel
label_desc: Use image node_id 3 for calling the Loss obj's underlying member method code with example usage: obj.forward(ploc, plabel, gloc, glabel) and returns: ret