(self, overlaps, gt_labels=None, gt_pids=None)
return AssignResult(
            num_gts, assigned_gt_inds, max_overlaps, labels=assigned_labels, 
                pids=assigned_pids)
Assign w.r.t. the overlaps of bboxes with gts.

        Args:
            overlaps (Tensor): Overlaps between k gt_bboxes and n bboxes,
                shape(k, n).
            gt_labels (Tensor, optional): Labels of k gt_bboxes, shape (k, ).

        Returns:
            :obj:`AssignResult`: The assign result.
Assign w.r.t. the overlaps of bboxes with gts.
Assign w . r . t . the overlaps of bboxes with gts .
def assign_wrt_overlaps(self, overlaps, gt_labels=None, gt_pids=None):
        """Assign w.r.t. the overlaps of bboxes with gts.

        Args:
            overlaps (Tensor): Overlaps between k gt_bboxes and n bboxes,
                shape(k, n).
            gt_labels (Tensor, optional): Labels of k gt_bboxes, shape (k, ).

        Returns:
            :obj:`AssignResult`: The assign result.
        """
        if overlaps.numel() == 0:
            raise ValueError('No gt or proposals')

        num_gts, num_bboxes = overlaps.size(0), overlaps.size(1)

        # 1. assign -1 by default
        assigned_gt_inds = overlaps.new_full((num_bboxes, ),
                                             -1,
                                             dtype=torch.long)

        # for each anchor, which gt best overlaps with it
        # for each anchor, the max iou of all gts
        max_overlaps, argmax_overlaps = overlaps.max(dim=0)
        # for each gt, which anchor best overlaps with it
        # for each gt, the max iou of all proposals
        gt_max_overlaps, gt_argmax_overlaps = overlaps.max(dim=1)

        # 2. assign negative: below
        if isinstance(self.neg_iou_thr, float):
            assigned_gt_inds[(max_overlaps >= 0)
                             & (max_overlaps < self.neg_iou_thr)] = 0
        elif isinstance(self.neg_iou_thr, tuple):
            assert len(self.neg_iou_thr) == 2
            assigned_gt_inds[(max_overlaps >= self.neg_iou_thr[0])
                             & (max_overlaps < self.neg_iou_thr[1])] = 0

        # 3. assign positive: above positive IoU threshold
        pos_inds = max_overlaps >= self.pos_iou_thr
        assigned_gt_inds[pos_inds] = argmax_overlaps[pos_inds] + 1

        # 4. assign fg: for each gt, proposals with highest IoU
        for i in range(num_gts):
            if gt_max_overlaps[i] >= self.min_pos_iou:
                if self.gt_max_assign_all:
                    max_iou_inds = overlaps[i, :] == gt_max_overlaps[i]
                    assigned_gt_inds[max_iou_inds] = i + 1
                else:
                    assigned_gt_inds[gt_argmax_overlaps[i]] = i + 1

        if gt_labels is not None:
            assigned_labels = assigned_gt_inds.new_zeros((num_bboxes, ))
            pos_inds = torch.nonzero(assigned_gt_inds > 0).squeeze()
            if pos_inds.numel() > 0:
                assigned_labels[pos_inds] = gt_labels[
                    assigned_gt_inds[pos_inds] - 1]
        else:
            assigned_labels = None

        if gt_pids is not None:
            assigned_pids = assigned_gt_inds.new_zeros((num_bboxes,))
            pos_inds = torch.nonzero(assigned_gt_inds > 0).squeeze()
            if pos_inds.numel() > 0:
                assigned_pids[pos_inds] = gt_pids[
                    assigned_gt_inds[pos_inds] - 1]
        else:
            assigned_pids = None

        return AssignResult(
            num_gts, assigned_gt_inds, max_overlaps, labels=assigned_labels, 
                pids=assigned_pids)
def assign_wrt_overlaps ( self , overlaps , gt_labels = None , gt_pids = None ) : if overlaps . numel ( ) == 0 : raise ValueError ( 'No gt or proposals' ) num_gts , num_bboxes = overlaps . size ( 0 ) , overlaps . size ( 1 ) # 1. assign -1 by default assigned_gt_inds = overlaps . new_full ( ( num_bboxes , ) , - 1 , dtype = torch . long ) # for each anchor, which gt best overlaps with it # for each anchor, the max iou of all gts max_overlaps , argmax_overlaps = overlaps . max ( dim = 0 ) # for each gt, which anchor best overlaps with it # for each gt, the max iou of all proposals gt_max_overlaps , gt_argmax_overlaps = overlaps . max ( dim = 1 ) # 2. assign negative: below if isinstance ( self . neg_iou_thr , float ) : assigned_gt_inds [ ( max_overlaps >= 0 ) & ( max_overlaps < self . neg_iou_thr ) ] = 0 elif isinstance ( self . neg_iou_thr , tuple ) : assert len ( self . neg_iou_thr ) == 2 assigned_gt_inds [ ( max_overlaps >= self . neg_iou_thr [ 0 ] ) & ( max_overlaps < self . neg_iou_thr [ 1 ] ) ] = 0 # 3. assign positive: above positive IoU threshold pos_inds = max_overlaps >= self . pos_iou_thr assigned_gt_inds [ pos_inds ] = argmax_overlaps [ pos_inds ] + 1 # 4. assign fg: for each gt, proposals with highest IoU for i in range ( num_gts ) : if gt_max_overlaps [ i ] >= self . min_pos_iou : if self . gt_max_assign_all : max_iou_inds = overlaps [ i , : ] == gt_max_overlaps [ i ] assigned_gt_inds [ max_iou_inds ] = i + 1 else : assigned_gt_inds [ gt_argmax_overlaps [ i ] ] = i + 1 if gt_labels is not None : assigned_labels = assigned_gt_inds . new_zeros ( ( num_bboxes , ) ) pos_inds = torch . nonzero ( assigned_gt_inds > 0 ) . squeeze ( ) if pos_inds . numel ( ) > 0 : assigned_labels [ pos_inds ] = gt_labels [ assigned_gt_inds [ pos_inds ] - 1 ] else : assigned_labels = None if gt_pids is not None : assigned_pids = assigned_gt_inds . new_zeros ( ( num_bboxes , ) ) pos_inds = torch . nonzero ( assigned_gt_inds > 0 ) . squeeze ( ) if pos_inds . numel ( ) > 0 : assigned_pids [ pos_inds ] = gt_pids [ assigned_gt_inds [ pos_inds ] - 1 ] else : assigned_pids = None return AssignResult ( num_gts , assigned_gt_inds , max_overlaps , labels = assigned_labels , pids = assigned_pids )