(self, locations, box_cls, box_regression, centerness, targets)
return cls_loss, reg_loss, centerness_loss
Arguments:
            locations (list[BoxList])
            box_cls (list[Tensor])
            box_regression (list[Tensor])
            centerness (list[Tensor])
            targets (list[BoxList])

        Returns:
            cls_loss (Tensor)
            reg_loss (Tensor)
            centerness_loss (Tensor)
Arguments:
            locations (list[BoxList])
            box_cls (list[Tensor])
            box_regression (list[Tensor])
            centerness (list[Tensor])
            targets (list[BoxList])
Arguments : locations ( list [ BoxList ] ) box_cls ( list [ Tensor ] ) box_regression ( list [ Tensor ] ) centerness ( list [ Tensor ] ) targets ( list [ BoxList ] )
def __call__(self, locations, box_cls, box_regression, centerness, targets):
        """
        Arguments:
            locations (list[BoxList])
            box_cls (list[Tensor])
            box_regression (list[Tensor])
            centerness (list[Tensor])
            targets (list[BoxList])

        Returns:
            cls_loss (Tensor)
            reg_loss (Tensor)
            centerness_loss (Tensor)
        """
        N = box_cls[0].size(0)
        num_classes = box_cls[0].size(1)
        labels, reg_targets = self.prepare_targets(locations, targets)

        box_cls_flatten = []
        box_regression_flatten = []
        centerness_flatten = []
        labels_flatten = []
        reg_targets_flatten = []
        for l in range(len(labels)):
            box_cls_flatten.append(box_cls[l].permute(0, 2, 3, 1).reshape(-1, num_classes))
            box_regression_flatten.append(box_regression[l].permute(0, 2, 3, 1).reshape(-1, 4))
            labels_flatten.append(labels[l].reshape(-1))
            reg_targets_flatten.append(reg_targets[l].reshape(-1, 4))
            centerness_flatten.append(centerness[l].reshape(-1))

        box_cls_flatten = torch.cat(box_cls_flatten, dim=0)
        box_regression_flatten = torch.cat(box_regression_flatten, dim=0)
        centerness_flatten = torch.cat(centerness_flatten, dim=0)
        labels_flatten = torch.cat(labels_flatten, dim=0)
        reg_targets_flatten = torch.cat(reg_targets_flatten, dim=0)

        pos_inds = torch.nonzero(labels_flatten > 0).squeeze(1)
        cls_loss = self.cls_loss_func(
            box_cls_flatten,
            labels_flatten.int()
        ) / (pos_inds.numel() + N)  # add N to avoid dividing by a zero

        box_regression_flatten = box_regression_flatten[pos_inds]
        reg_targets_flatten = reg_targets_flatten[pos_inds]
        centerness_flatten = centerness_flatten[pos_inds]

        if pos_inds.numel() > 0:
            centerness_targets = self.compute_centerness_targets(reg_targets_flatten)
            reg_loss = self.box_reg_loss_func(
                box_regression_flatten,
                reg_targets_flatten,
                centerness_targets
            )
            centerness_loss = self.centerness_loss_func(
                centerness_flatten,
                centerness_targets
            )
        else:
            reg_loss = box_regression_flatten.sum()
            centerness_loss = centerness_flatten.sum()

        return cls_loss, reg_loss, centerness_loss
def __call__ ( self , locations , box_cls , box_regression , centerness , targets ) : N = box_cls [ 0 ] . size ( 0 ) num_classes = box_cls [ 0 ] . size ( 1 ) labels , reg_targets = self . prepare_targets ( locations , targets ) box_cls_flatten = [ ] box_regression_flatten = [ ] centerness_flatten = [ ] labels_flatten = [ ] reg_targets_flatten = [ ] for l in range ( len ( labels ) ) : box_cls_flatten . append ( box_cls [ l ] . permute ( 0 , 2 , 3 , 1 ) . reshape ( - 1 , num_classes ) ) box_regression_flatten . append ( box_regression [ l ] . permute ( 0 , 2 , 3 , 1 ) . reshape ( - 1 , 4 ) ) labels_flatten . append ( labels [ l ] . reshape ( - 1 ) ) reg_targets_flatten . append ( reg_targets [ l ] . reshape ( - 1 , 4 ) ) centerness_flatten . append ( centerness [ l ] . reshape ( - 1 ) ) box_cls_flatten = torch . cat ( box_cls_flatten , dim = 0 ) box_regression_flatten = torch . cat ( box_regression_flatten , dim = 0 ) centerness_flatten = torch . cat ( centerness_flatten , dim = 0 ) labels_flatten = torch . cat ( labels_flatten , dim = 0 ) reg_targets_flatten = torch . cat ( reg_targets_flatten , dim = 0 ) pos_inds = torch . nonzero ( labels_flatten > 0 ) . squeeze ( 1 ) cls_loss = self . cls_loss_func ( box_cls_flatten , labels_flatten . int ( ) ) / ( pos_inds . numel ( ) + N ) # add N to avoid dividing by a zero box_regression_flatten = box_regression_flatten [ pos_inds ] reg_targets_flatten = reg_targets_flatten [ pos_inds ] centerness_flatten = centerness_flatten [ pos_inds ] if pos_inds . numel ( ) > 0 : centerness_targets = self . compute_centerness_targets ( reg_targets_flatten ) reg_loss = self . box_reg_loss_func ( box_regression_flatten , reg_targets_flatten , centerness_targets ) centerness_loss = self . centerness_loss_func ( centerness_flatten , centerness_targets ) else : reg_loss = box_regression_flatten . sum ( ) centerness_loss = centerness_flatten . sum ( ) return cls_loss , reg_loss , centerness_loss