(
            self, anchors, box_cls, box_regression)
return results
Arguments:
            anchors: list[BoxList]
            box_cls: tensor of size N, A * C, H, W
            box_regression: tensor of size N, A * 4, H, W
Arguments:
            anchors: list[BoxList]
            box_cls: tensor of size N, A * C, H, W
            box_regression: tensor of size N, A * 4, H, W
Arguments : anchors : list [ BoxList ] box_cls : tensor of size N A * C H W box_regression : tensor of size N A * 4 H W
def forward_for_single_feature_map(
            self, anchors, box_cls, box_regression):
        """
        Arguments:
            anchors: list[BoxList]
            box_cls: tensor of size N, A * C, H, W
            box_regression: tensor of size N, A * 4, H, W
        """
        device = box_cls.device
        N, _, H, W = box_cls.shape
        A = box_regression.size(1) // 4
        C = box_cls.size(1) // A

        # put in the same format as anchors
        box_cls = permute_and_flatten(box_cls, N, A, C, H, W)
        box_cls = box_cls.sigmoid()

        box_regression = permute_and_flatten(box_regression, N, A, 4, H, W)
        box_regression = box_regression.reshape(N, -1, 4)

        num_anchors = A * H * W

        candidate_inds = box_cls > self.pre_nms_thresh

        pre_nms_top_n = candidate_inds.view(N, -1).sum(1)
        pre_nms_top_n = pre_nms_top_n.clamp(max=self.pre_nms_top_n)

        results = []
        for per_box_cls, per_box_regression, per_pre_nms_top_n, \
        per_candidate_inds, per_anchors in zip(
            box_cls,
            box_regression,
            pre_nms_top_n,
            candidate_inds,
            anchors):

            # Sort and select TopN
            # TODO most of this can be made out of the loop for
            # all images. 
            # TODO:Yang: Not easy to do. Because the numbers of detections are
            # different in each image. Therefore, this part needs to be done
            # per image. 
            per_box_cls = per_box_cls[per_candidate_inds]
 
            per_box_cls, top_k_indices = \
                    per_box_cls.topk(per_pre_nms_top_n, sorted=False)

            per_candidate_nonzeros = \
                    per_candidate_inds.nonzero()[top_k_indices, :]

            per_box_loc = per_candidate_nonzeros[:, 0]
            per_class = per_candidate_nonzeros[:, 1]
            per_class += 1

            detections = self.box_coder.decode(
                per_box_regression[per_box_loc, :].view(-1, 4),
                per_anchors.bbox[per_box_loc, :].view(-1, 4)
            )

            boxlist = BoxList(detections, per_anchors.size, mode="xyxy")
            boxlist.add_field("labels", per_class)
            boxlist.add_field("scores", per_box_cls)
            boxlist = boxlist.clip_to_image(remove_empty=False)
            boxlist = remove_small_boxes(boxlist, self.min_size)
            results.append(boxlist)

        return results
def forward_for_single_feature_map ( self , anchors , box_cls , box_regression ) : device = box_cls . device N , _ , H , W = box_cls . shape A = box_regression . size ( 1 ) // 4 C = box_cls . size ( 1 ) // A # put in the same format as anchors box_cls = permute_and_flatten ( box_cls , N , A , C , H , W ) box_cls = box_cls . sigmoid ( ) box_regression = permute_and_flatten ( box_regression , N , A , 4 , H , W ) box_regression = box_regression . reshape ( N , - 1 , 4 ) num_anchors = A * H * W candidate_inds = box_cls > self . pre_nms_thresh pre_nms_top_n = candidate_inds . view ( N , - 1 ) . sum ( 1 ) pre_nms_top_n = pre_nms_top_n . clamp ( max = self . pre_nms_top_n ) results = [ ] for per_box_cls , per_box_regression , per_pre_nms_top_n , per_candidate_inds , per_anchors in zip ( box_cls , box_regression , pre_nms_top_n , candidate_inds , anchors ) : # Sort and select TopN # TODO most of this can be made out of the loop for # all images.  # TODO:Yang: Not easy to do. Because the numbers of detections are # different in each image. Therefore, this part needs to be done # per image.  per_box_cls = per_box_cls [ per_candidate_inds ] per_box_cls , top_k_indices = per_box_cls . topk ( per_pre_nms_top_n , sorted = False ) per_candidate_nonzeros = per_candidate_inds . nonzero ( ) [ top_k_indices , : ] per_box_loc = per_candidate_nonzeros [ : , 0 ] per_class = per_candidate_nonzeros [ : , 1 ] per_class += 1 detections = self . box_coder . decode ( per_box_regression [ per_box_loc , : ] . view ( - 1 , 4 ) , per_anchors . bbox [ per_box_loc , : ] . view ( - 1 , 4 ) ) boxlist = BoxList ( detections , per_anchors . size , mode = "xyxy" ) boxlist . add_field ( "labels" , per_class ) boxlist . add_field ( "scores" , per_box_cls ) boxlist = boxlist . clip_to_image ( remove_empty = False ) boxlist = remove_small_boxes ( boxlist , self . min_size ) results . append ( boxlist ) return results