(
        locs, confs, roi_indices, gt_locs, gt_labels, batchsize)
return loc_loss, conf_loss
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`.
Loss function for Head (post).
Loss function for Head ( post ) .
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
def bbox_head_loss_post ( locs , confs , roi_indices , gt_locs , gt_labels , batchsize ) : 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