def forward(self, imgs, bboxes, labels, scale):
    'Forward Faster R-CNN and calculate losses.\n\n        Here are notations used.\n\n        * :math:`N` is the batch size.\n        * :math:`R` is the number of bounding boxes per image.\n\n        Currently, only :math:`N=1` is supported.\n\n        Args:\n            imgs (~torch.autograd.Variable): A variable with a batch of images.\n            bboxes (~torch.autograd.Variable): A batch of bounding boxes.\n                Its shape is :math:`(N, R, 4)`.\n            labels (~torch.autograd..Variable): A batch of labels.\n                Its shape is :math:`(N, R)`. The background is excluded from\n                the definition, which means that the range of the value\n                is :math:`[0, L - 1]`. :math:`L` is the number of foreground\n                classes.\n            scale (float): Amount of scaling applied to\n                the raw image during preprocessing.\n\n        Returns:\n            namedtuple of 5 losses\n        '
    n = bboxes.shape[0]
    if (n != 1):
        raise ValueError('Currently only batch size 1 is supported.')
    (_, _, H, W) = imgs.shape
    img_size = (H, W)
    features = self.faster_rcnn.extractor(imgs)
    (rpn_locs, rpn_scores, rois, roi_indices, anchor) = self.faster_rcnn.rpn(features, img_size, scale)
    bbox = bboxes[0]
    label = labels[0]
    rpn_score = rpn_scores[0]
    rpn_loc = rpn_locs[0]
    roi = rois
    (sample_roi, gt_roi_loc, gt_roi_label) = self.proposal_target_creator(roi, at.tonumpy(bbox), at.tonumpy(label), self.loc_normalize_mean, self.loc_normalize_std)
    sample_roi_index = t.zeros(len(sample_roi))
    (roi_cls_loc, roi_score) = self.faster_rcnn.head(features, sample_roi, sample_roi_index)
    (gt_rpn_loc, gt_rpn_label) = self.anchor_target_creator(at.tonumpy(bbox), anchor, img_size)
    gt_rpn_label = at.totensor(gt_rpn_label).long()
    gt_rpn_loc = at.totensor(gt_rpn_loc)
    rpn_loc_loss = _fast_rcnn_loc_loss(rpn_loc, gt_rpn_loc, gt_rpn_label.data, self.rpn_sigma)
    rpn_cls_loss = F.cross_entropy(rpn_score, gt_rpn_label.cuda(), ignore_index=(- 1))
    _gt_rpn_label = gt_rpn_label[(gt_rpn_label > (- 1))]
    _rpn_score = at.tonumpy(rpn_score)[(at.tonumpy(gt_rpn_label) > (- 1))]
    self.rpn_cm.add(at.totensor(_rpn_score, False), _gt_rpn_label.data.long())
    n_sample = roi_cls_loc.shape[0]
    roi_cls_loc = roi_cls_loc.view(n_sample, (- 1), 4)
    roi_loc = roi_cls_loc[(t.arange(0, n_sample).long().cuda(), at.totensor(gt_roi_label).long())]
    gt_roi_label = at.totensor(gt_roi_label).long()
    gt_roi_loc = at.totensor(gt_roi_loc)
    roi_loc_loss = _fast_rcnn_loc_loss(roi_loc.contiguous(), gt_roi_loc, gt_roi_label.data, self.roi_sigma)
    roi_cls_loss = nn.CrossEntropyLoss()(roi_score, gt_roi_label.cuda())
    self.roi_cm.add(at.totensor(roi_score, False), gt_roi_label.data.long())
    losses = [rpn_loc_loss, rpn_cls_loss, roi_loc_loss, roi_cls_loss]
    losses = (losses + [sum(losses)])
    return LossTuple(*losses)
Forward Faster R-CNN and calculate losses.

Here are notations used.

* :math:`N` is the batch size.
* :math:`R` is the number of bounding boxes per image.

Currently, only :math:`N=1` is supported.

Args:
    imgs (~torch.autograd.Variable): A variable with a batch of images.
    bboxes (~torch.autograd.Variable): A batch of bounding boxes.
        Its shape is :math:`(N, R, 4)`.
    labels (~torch.autograd..Variable): A batch of labels.
        Its shape is :math:`(N, R)`. The background is excluded from
        the definition, which means that the range of the value
        is :math:`[0, L - 1]`. :math:`L` is the number of foreground
        classes.
    scale (float): Amount of scaling applied to
        the raw image during preprocessing.

Returns:
    namedtuple of 5 losses
def forward(self, imgs, bboxes, labels, scale):
    'Forward Faster R-CNN and calculate losses.\n\n        Here are notations used.\n\n        * :math:`N` is the batch size.\n        * :math:`R` is the number of bounding boxes per image.\n\n        Currently, only :math:`N=1` is supported.\n\n        Args:\n            imgs (~torch.autograd.Variable): A variable with a batch of images.\n            bboxes (~torch.autograd.Variable): A batch of bounding boxes.\n                Its shape is :math:`(N, R, 4)`.\n            labels (~torch.autograd..Variable): A batch of labels.\n                Its shape is :math:`(N, R)`. The background is excluded from\n                the definition, which means that the range of the value\n                is :math:`[0, L - 1]`. :math:`L` is the number of foreground\n                classes.\n            scale (float): Amount of scaling applied to\n                the raw image during preprocessing.\n\n        Returns:\n            namedtuple of 5 losses\n        '
    n = bboxes.shape[0]
    if (n != 1):
        raise ValueError('Currently only batch size 1 is supported.')
    (_, _, H, W) = imgs.shape
    img_size = (H, W)
    features = self.faster_rcnn.extractor(imgs)
    (rpn_locs, rpn_scores, rois, roi_indices, anchor) = self.faster_rcnn.rpn(features, img_size, scale)
    bbox = bboxes[0]
    label = labels[0]
    rpn_score = rpn_scores[0]
    rpn_loc = rpn_locs[0]
    roi = rois
    (sample_roi, gt_roi_loc, gt_roi_label) = self.proposal_target_creator(roi, at.tonumpy(bbox), at.tonumpy(label), self.loc_normalize_mean, self.loc_normalize_std)
    sample_roi_index = t.zeros(len(sample_roi))
    (roi_cls_loc, roi_score) = self.faster_rcnn.head(features, sample_roi, sample_roi_index)
    (gt_rpn_loc, gt_rpn_label) = self.anchor_target_creator(at.tonumpy(bbox), anchor, img_size)
    gt_rpn_label = at.totensor(gt_rpn_label).long()
    gt_rpn_loc = at.totensor(gt_rpn_loc)
    rpn_loc_loss = _fast_rcnn_loc_loss(rpn_loc, gt_rpn_loc, gt_rpn_label.data, self.rpn_sigma)
    rpn_cls_loss = F.cross_entropy(rpn_score, gt_rpn_label.cuda(), ignore_index=(- 1))
    _gt_rpn_label = gt_rpn_label[(gt_rpn_label > (- 1))]
    _rpn_score = at.tonumpy(rpn_score)[(at.tonumpy(gt_rpn_label) > (- 1))]
    self.rpn_cm.add(at.totensor(_rpn_score, False), _gt_rpn_label.data.long())
    n_sample = roi_cls_loc.shape[0]
    roi_cls_loc = roi_cls_loc.view(n_sample, (- 1), 4)
    roi_loc = roi_cls_loc[(t.arange(0, n_sample).long().cuda(), at.totensor(gt_roi_label).long())]
    gt_roi_label = at.totensor(gt_roi_label).long()
    gt_roi_loc = at.totensor(gt_roi_loc)
    roi_loc_loss = _fast_rcnn_loc_loss(roi_loc.contiguous(), gt_roi_loc, gt_roi_label.data, self.roi_sigma)
    roi_cls_loss = nn.CrossEntropyLoss()(roi_score, gt_roi_label.cuda())
    self.roi_cm.add(at.totensor(roi_score, False), gt_roi_label.data.long())
    losses = [rpn_loc_loss, rpn_cls_loss, roi_loc_loss, roi_cls_loss]
    losses = (losses + [sum(losses)])
    return LossTuple(*losses)