code: def bbox_head_loss_post(
      locs, confs, roi_indices, gt_locs, gt_labels, batchsize
  ):
      """Loss function for Head (post).
  
      Args:
          locs (array): An array whose shape is :math:`(R, n\_class, 4)`,
              where :math:`R` is the total number of RoIs in the given batch.
          confs (array): An iterable of arrays whose shape is
              :math:`(R, n\_class)`.
          roi_indices (list of arrays): A list of arrays returned by
              :func:`bbox_head_locs_pre`.
          gt_locs (list of arrays): A list of arrays returned by
              :func:`bbox_head_locs_pre`.
          gt_labels (list of arrays): A list of arrays returned by
              :func:`bbox_head_locs_pre`.
          batchsize (int): The size of batch.
  
      Returns:
          tuple of two variables:
          :obj:`loc_loss` and :obj:`conf_loss`.
      """
  
      xp = cuda.get_array_module(locs.array, confs.array)
  
      roi_indices = xp.hstack(roi_indices).astype(np.int32)
      gt_locs = xp.vstack(gt_locs).astype(np.float32)
      gt_labels = xp.hstack(gt_labels).astype(np.int32)
  
      loc_loss = 0
      conf_loss = 0
      for i in np.unique(cuda.to_cpu(roi_indices)):
          mask = roi_indices == i
          gt_loc = gt_locs[mask]
          gt_label = gt_labels[mask]
  
          n_sample = mask.sum()
          loc_loss += (
              F.sum(
                  smooth_l1(
                      locs[mask][
                          xp.where(gt_label > 0)[0],
                          gt_label[gt_label > 0],
                      ],
                      gt_loc[gt_label > 0],
                      1,
                  )
              )
              / n_sample
          )
          conf_loss += F.softmax_cross_entropy(confs[mask], gt_label)
  
      loc_loss /= batchsize
      conf_loss /= batchsize
  
      return loc_loss, conf_loss
  
imports: from __future__ import division
  import numpy
  import chainer
  from chainer.backends import cuda
  import chainer.functions
  from chainer import initializers
  import chainer.links
  from chainercv.links.model.fpn.misc import argsort
  from chainercv.links.model.fpn.misc import choice
  from chainercv.links.model.fpn.misc import exp_clip
  from chainercv.links.model.fpn.misc import smooth_l1
  from chainercv import utils
label_desc: Use image node_id 2 for calling a global function with example usage: bbox_head_loss_post(locs, confs, roi_indices, gt_locs, gt_labels, batchsize) and returns: loc_loss,  conf_loss