class_docstr: Single-Shot Multibox Object Detection Loss.
  
  .. note::
  
      Since cross device synchronization is required to compute batch-wise statistics,
      it is slightly sub-optimal compared with non-sync version. However, we find this
      is better for converged model performance.
  
  Parameters
  ----------
  negative_mining_ratio : float, default is 3
      Ratio of negative vs. positive samples.
  rho : float, default is 1.0
      Threshold for trimmed mean estimators. This is the smooth parameter for the
      L1-L2 transition.
  lambd : float, default is 1.0
      Relative weight between classification and box regression loss.
      The overall loss is computed as :math:`L = loss_{class} + \lambda \times loss_{loc}`.
  min_hard_negatives : int, default is 0
      Minimum number of negatives samples.
class_docstr_tok: ["Single-Shot","Multibox","Object","Detection","Loss",".","..","note",":",":","Since","cross","device","synchronization","is","required","to","compute","batch-wise","statistics",",","it","is","slightly","sub-optimal","compared","with","non-sync","version",".","However",",","we","find","this","is","better","for","converged","model","performance",".","Parameters","--","--","--","--","--","negative_mining_ratio",":","float",",","default","is","3","Ratio","of","negative","vs.","positive","samples",".","rho",":","float",",","default","is","1.0","Threshold","for","trimmed","mean","estimators",".","This","is","the","smooth","parameter","for","the","L1-L2","transition",".","lambd",":","float",",","default","is","1.0","Relative","weight","between","classification","and","box","regression","loss",".","The","overall","loss","is","computed","as",":","math",":","`","L","=","loss_","{","class","}","+","\\lambda","\\times","loss_","{","loc","}","`",".","min_hard_negatives",":","int",",","default","is","0","Minimum","number","of","negatives","samples","."]
docstr: Compute loss in entire batch across devices.
  
  Parameters
  ----------
  cls_pred : mxnet.nd.NDArray
  Predicted classes.
  box_pred : mxnet.nd.NDArray
  Predicted bounding-boxes.
  cls_target : mxnet.nd.NDArray
  Ground-truth classes.
  box_target : mxnet.nd.NDArray
  Ground-truth bounding-boxes.
  
  Returns
  -------
  tuple of NDArrays
      sum_losses : array with containing the sum of
          class prediction and bounding-box regression loss.
      cls_losses : array of class prediction loss.
      box_losses : array of box regression L1 loss.
docstr_tok: ["Compute","loss","in","entire","batch","across","devices",".","Parameters","--","--","--","--","--","cls_pred",":","mxnet.nd.NDArray","Predicted","classes",".","box_pred",":","mxnet.nd.NDArray","Predicted","bounding-boxes",".","cls_target",":","mxnet.nd.NDArray","Ground-truth","classes",".","box_target",":","mxnet.nd.NDArray","Ground-truth","bounding-boxes",".","Returns","--","--","--","-","tuple","of","NDArrays","sum_losses",":","array","with","containing","the","sum","of","class","prediction","and","bounding-box","regression","loss",".","cls_losses",":","array","of","class","prediction","loss",".","box_losses",":","array","of","box","regression","L1","loss","."]
code: def forward(self, cls_pred, box_pred, cls_target, box_target):
      """Compute loss in entire batch across devices.
  
      Parameters
      ----------
      cls_pred : mxnet.nd.NDArray
      Predicted classes.
      box_pred : mxnet.nd.NDArray
      Predicted bounding-boxes.
      cls_target : mxnet.nd.NDArray
      Ground-truth classes.
      box_target : mxnet.nd.NDArray
      Ground-truth bounding-boxes.
  
      Returns
      -------
      tuple of NDArrays
          sum_losses : array with containing the sum of
              class prediction and bounding-box regression loss.
          cls_losses : array of class prediction loss.
          box_losses : array of box regression L1 loss.
  
      """
      # require results across different devices at this time
      cls_pred, box_pred, cls_target, box_target = [
          _as_list(x)
          for x in (cls_pred, box_pred, cls_target, box_target)
      ]
      # cross device reduction to obtain positive samples in entire batch
      num_pos = []
      for cp, bp, ct, bt in zip(
          *[cls_pred, box_pred, cls_target, box_target]
      ):
          pos_samples = ct > 0
          num_pos.append(pos_samples.sum())
      num_pos_all = sum([p.asscalar() for p in num_pos])
      if num_pos_all < 1 and self._min_hard_negatives < 1:
          # no positive samples and no hard negatives, return dummy losses
          cls_losses = [nd.sum(cp * 0) for cp in cls_pred]
          box_losses = [nd.sum(bp * 0) for bp in box_pred]
          sum_losses = [
              nd.sum(cp * 0) + nd.sum(bp * 0)
              for cp, bp in zip(cls_pred, box_pred)
          ]
          return sum_losses, cls_losses, box_losses
  
      # compute element-wise cross entropy loss and sort, then perform negative mining
      cls_losses = []
      box_losses = []
      sum_losses = []
      for cp, bp, ct, bt in zip(
          *[cls_pred, box_pred, cls_target, box_target]
      ):
          pred = nd.log_softmax(cp, axis=-1)
          pos = ct > 0
          cls_loss = -nd.pick(pred, ct, axis=-1, keepdims=False)
          rank = (cls_loss * (pos - 1)).argsort(axis=1).argsort(axis=1)
          hard_negative = rank < nd.maximum(
              self._min_hard_negatives,
              pos.sum(axis=1) * self._negative_mining_ratio,
          ).expand_dims(-1)
          # mask out if not positive or negative
          cls_loss = nd.where(
              (pos + hard_negative) > 0,
              cls_loss,
              nd.zeros_like(cls_loss),
          )
          cls_losses.append(
              nd.sum(cls_loss, axis=0, exclude=True)
              / max(1.0, num_pos_all)
          )
  
          bp = _reshape_like(nd, bp, bt)
          box_loss = nd.abs(bp - bt)
          box_loss = nd.where(
              box_loss > self._rho,
              box_loss - 0.5 * self._rho,
              (0.5 / self._rho) * nd.square(box_loss),
          )
          # box loss only apply to positive samples
          box_loss = box_loss * pos.expand_dims(axis=-1)
          box_losses.append(
              nd.sum(box_loss, axis=0, exclude=True)
              / max(1.0, num_pos_all)
          )
          sum_losses.append(
              cls_losses[-1] + self._lambd * box_losses[-1]
          )
  
      return sum_losses, cls_losses, box_losses
  
imports: from __future__ import absolute_import
  from mxnet import gluon
  from mxnet import nd
  from mxnet.gluon.loss import Loss, _apply_weighting, _reshape_like
label_desc: Use image node_id 2 for calling the SSDMultiBoxLoss obj's underlying member method code with example usage: obj.forward(cls_pred, box_pred, cls_target, box_target) and returns: sum_losses,  cls_losses,  box_losses, sum_losses,  cls_losses,  box_losses