def get_bboxes(self,
                   all_cls_scores,
                   all_bbox_preds,
                   img_shapes,
                   scale_factors,
                   rescale=False,
                   with_nms=False):
        """Transform network outputs for a batch into bbox predictions.

        Args:
            all_cls_scores (Tensor): Classification score of all
                decoder layers, has shape
                [nb_dec, bs, num_query, cls_out_channels].
            all_bbox_preds (Tensor): Sigmoid regression
                outputs of all decode layers. Each is a 4D-tensor with
                normalized coordinate format (cx, cy, w, h) and shape
                [nb_dec, bs, num_query, 4].
            enc_cls_scores (Tensor): Classification scores of
                points on encode feature map , has shape
                (N, h*w, num_classes). Only be passed when as_two_stage is
                True, otherwise is None.
            enc_bbox_preds (Tensor): Regression results of each points
                on the encode feature map, has shape (N, h*w, 4). Only be
                passed when as_two_stage is True, otherwise is None.
            img_metas (list[dict]): Meta information of each image.
            rescale (bool, optional): If True, return boxes in original
                image space. Default False.

        Returns:
            list[list[Tensor, Tensor]]: Each item in result_list is 2-tuple. \
                The first item is an (n, 5) tensor, where the first 4 columns \
                are bounding box positions (tl_x, tl_y, br_x, br_y) and the \
                5-th column is a score between 0 and 1. The second item is a \
                (n,) tensor where each item is the predicted class label of \
                the corresponding box.
        """
        cls_scores = all_cls_scores[-1]
        bbox_preds = all_bbox_preds[-1]
        assert len(cls_scores) == len(bbox_preds)
        max_per_img = self.test_cfg.get('max_per_img', self.num_query)

        if with_nms:
            max_per_img = self.num_query

        # exclude background
        if self.loss_cls.use_sigmoid:
            cls_scores = F.sigmoid(cls_scores)
            scores, index = cls_scores.flatten(1).topk(max_per_img, axis=-1)
            det_labels = index % self.num_classes
            index = index // self.num_classes
            batch_ind = paddle.arange(end=scores.shape[0]).unsqueeze(-1).tile(
                [1, max_per_img]
            )
            index = paddle.stack([batch_ind, index], axis=-1)
            bbox_preds = paddle.gather_nd(bbox_preds, index)
            nms_scores = paddle.gather_nd(cls_scores, index) 
        else:
            cls_scores = F.softmax(cls_scores, axis=-1)[..., :-1]
            scores, det_labels = cls_scores.max(-1), cls_scores.argmax(-1)
            scores, index = scores.topk(max_per_img, axis=-1)
            batch_ind = paddle.arange(
                end=scores.shape[0]).unsqueeze(-1).tile([1, max_per_img]
            )
            index = paddle.stack([batch_ind, index], axis=-1)
            det_labels = paddle.gather_nd(det_labels, index)
            bbox_preds = paddle.gather_nd(bbox_preds, index)
            nms_scores = paddle.gather_nd(cls_scores, index)

        det_bboxes = bbox_cxcywh_to_xyxy(bbox_preds)
        out_shapes = img_shapes.flip(1).tile([1, 2]).unsqueeze(1)
        det_bboxes *= out_shapes
        det_bboxes = det_bboxes.minimum(out_shapes).clip(0)

        if rescale:
            det_bboxes /= paddle.concat([scale_factors[:, ::-1], scale_factors[:, ::-1]], -1).unsqueeze(1)

        if with_nms:
            mask_scores = paddle.full_like(nms_scores, -0.1)
            B, N, _ = nms_scores.shape
            batch_ind, num_ind = paddle.arange(B)[:, None], paddle.arange(N)[None, :]
            mask_scores[batch_ind, num_ind, det_labels] = nms_scores[batch_ind, num_ind, det_labels]
            bbox_pred, bbox_num, _ = self.nms(det_bboxes, mask_scores.transpose((0, 2, 1)))
        else:
            det_bboxes = paddle.concat((scores.unsqueeze(-1), det_bboxes.astype('float32')), -1)
            bbox_pred = paddle.concat((det_labels.unsqueeze(-1).astype('float32'),det_bboxes), -1)
            bbox_pred = bbox_pred.reshape([-1, 6])
            bbox_num = paddle.to_tensor(
                max_per_img, dtype='int32').tile([det_bboxes.shape[0]])

        return bbox_pred, bbox_num
Transform network outputs for a batch into bbox predictions.

        Args:
            all_cls_scores (Tensor): Classification score of all
                decoder layers, has shape
                [nb_dec, bs, num_query, cls_out_channels].
            all_bbox_preds (Tensor): Sigmoid regression
                outputs of all decode layers. Each is a 4D-tensor with
                normalized coordinate format (cx, cy, w, h) and shape
                [nb_dec, bs, num_query, 4].
            enc_cls_scores (Tensor): Classification scores of
                points on encode feature map , has shape
                (N, h*w, num_classes). Only be passed when as_two_stage is
                True, otherwise is None.
            enc_bbox_preds (Tensor): Regression results of each points
                on the encode feature map, has shape (N, h*w, 4). Only be
                passed when as_two_stage is True, otherwise is None.
            img_metas (list[dict]): Meta information of each image.
            rescale (bool, optional): If True, return boxes in original
                image space. Default False.

        Returns:
            list[list[Tensor, Tensor]]: Each item in result_list is 2-tuple.                 The first item is an (n, 5) tensor, where the first 4 columns                 are bounding box positions (tl_x, tl_y, br_x, br_y) and the                 5-th column is a score between 0 and 1. The second item is a                 (n,) tensor where each item is the predicted class label of                 the corresponding box.
        
ppdet/modeling/heads/co_deformable_detr_head.py