(self,
               assign_result,
               bboxes,
               gt_bboxes,
               gt_labels=None,
               gt_pids=None,
               **kwargs)
return SamplingResult(pos_inds, neg_inds, bboxes, gt_bboxes,
                              assign_result, gt_flags)
Sample positive and negative bboxes.

        This is a simple implementation of bbox sampling given candidates,
        assigning results and ground truth bboxes.

        Args:
            assign_result (:obj:`AssignResult`): Bbox assigning results.
            bboxes (Tensor): Boxes to be sampled from.
            gt_bboxes (Tensor): Ground truth bboxes.
            gt_labels (Tensor, optional): Class labels of ground truth bboxes.
            gt_pids (Tensor, optional): identity labels of ground truth bboxes
        Returns:
            :obj:`SamplingResult`: Sampling result.
Sample positive and negative bboxes.
Sample positive and negative bboxes .
def sample(self,
               assign_result,
               bboxes,
               gt_bboxes,
               gt_labels=None,
               gt_pids=None,
               **kwargs):
        """Sample positive and negative bboxes.

        This is a simple implementation of bbox sampling given candidates,
        assigning results and ground truth bboxes.

        Args:
            assign_result (:obj:`AssignResult`): Bbox assigning results.
            bboxes (Tensor): Boxes to be sampled from.
            gt_bboxes (Tensor): Ground truth bboxes.
            gt_labels (Tensor, optional): Class labels of ground truth bboxes.
            gt_pids (Tensor, optional): identity labels of ground truth bboxes
        Returns:
            :obj:`SamplingResult`: Sampling result.
        """
        bboxes = bboxes[:, :4]

        gt_flags = bboxes.new_zeros((bboxes.shape[0], ), dtype=torch.uint8)
        if self.add_gt_as_proposals:
            bboxes = torch.cat([gt_bboxes, bboxes], dim=0)
            assign_result.add_gt_(gt_labels, gt_pids)
            gt_ones = bboxes.new_ones(gt_bboxes.shape[0], dtype=torch.uint8)
            gt_flags = torch.cat([gt_ones, gt_flags])

        num_expected_pos = int(self.num * self.pos_fraction)
        pos_inds = self.pos_sampler._sample_pos(
            assign_result, num_expected_pos, bboxes=bboxes, **kwargs)
        # We found that sampled indices have duplicated items occasionally.
        # (may be a bug of PyTorch)
        pos_inds = pos_inds.unique()
        num_sampled_pos = pos_inds.numel()
        num_expected_neg = self.num - num_sampled_pos
        if self.neg_pos_ub >= 0:
            _pos = max(1, num_sampled_pos)
            neg_upper_bound = int(self.neg_pos_ub * _pos)
            if num_expected_neg > neg_upper_bound:
                num_expected_neg = neg_upper_bound
        neg_inds = self.neg_sampler._sample_neg(
            assign_result, num_expected_neg, bboxes=bboxes, **kwargs)
        neg_inds = neg_inds.unique()

        return SamplingResult(pos_inds, neg_inds, bboxes, gt_bboxes,
                              assign_result, gt_flags)
def sample ( self , assign_result , bboxes , gt_bboxes , gt_labels = None , gt_pids = None , * * kwargs ) : bboxes = bboxes [ : , : 4 ] gt_flags = bboxes . new_zeros ( ( bboxes . shape [ 0 ] , ) , dtype = torch . uint8 ) if self . add_gt_as_proposals : bboxes = torch . cat ( [ gt_bboxes , bboxes ] , dim = 0 ) assign_result . add_gt_ ( gt_labels , gt_pids ) gt_ones = bboxes . new_ones ( gt_bboxes . shape [ 0 ] , dtype = torch . uint8 ) gt_flags = torch . cat ( [ gt_ones , gt_flags ] ) num_expected_pos = int ( self . num * self . pos_fraction ) pos_inds = self . pos_sampler . _sample_pos ( assign_result , num_expected_pos , bboxes = bboxes , * * kwargs ) # We found that sampled indices have duplicated items occasionally. # (may be a bug of PyTorch) pos_inds = pos_inds . unique ( ) num_sampled_pos = pos_inds . numel ( ) num_expected_neg = self . num - num_sampled_pos if self . neg_pos_ub >= 0 : _pos = max ( 1 , num_sampled_pos ) neg_upper_bound = int ( self . neg_pos_ub * _pos ) if num_expected_neg > neg_upper_bound : num_expected_neg = neg_upper_bound neg_inds = self . neg_sampler . _sample_neg ( assign_result , num_expected_neg , bboxes = bboxes , * * kwargs ) neg_inds = neg_inds . unique ( ) return SamplingResult ( pos_inds , neg_inds , bboxes , gt_bboxes , assign_result , gt_flags )