def gen_encoder_output_proposals(self, memory, memory_padding_mask, spatial_shapes):
        """Generate proposals from encoded memory.

        Args:
            memory (Tensor): The output of encoder, has shape
                (bs, num_key, embed_dim). num_key is equal the number of points
                on feature map from all level.
            memory_padding_mask (Tensor): Padding mask for memory.
                has shape (bs, num_key).
            spatial_shapes (Tensor): The shape of all feature maps.
                has shape (num_level, 2).

        Returns:
            tuple: A tuple of feature map and bbox prediction.

                - output_memory (Tensor): The input of decoder, has shape
                    (bs, num_key, embed_dim). num_key is equal the number of
                    points on feature map from all levels.
                - output_proposals (Tensor): The normalized proposal
                    after a inverse sigmoid, has shape (bs, num_keys, 4).
        """

        N, S, C = memory.shape
        proposals = []
        _cur = 0
        
        for lvl, (H, W) in enumerate(spatial_shapes):
            mask_flatten_ = memory_padding_mask[:, _cur : (_cur + H * W)].reshape(
                [N, H, W, 1]
            )

            valid_H = paddle.sum(mask_flatten_[:, :, 0, 0].astype("float32"), 1)
            valid_W = paddle.sum(mask_flatten_[:, 0, :, 0].astype("float32"), 1)

            grid_y, grid_x = paddle.meshgrid(
                paddle.linspace(0, H - 1, H.astype(paddle.int32), dtype="float32"),
                paddle.linspace(0, W - 1, W.astype(paddle.int32), dtype="float32"),
            )
            grid = paddle.concat([grid_x.unsqueeze(-1), grid_y.unsqueeze(-1)], -1)

            scale = paddle.concat(
                [valid_W.unsqueeze(-1), valid_H.unsqueeze(-1)], 1
            ).reshape([N, 1, 1, 2])
            grid = (grid.unsqueeze(0).expand((N, -1, -1, -1)) + 0.5) / scale
            wh = paddle.ones_like(grid) * 0.05 * (2.0**lvl)
            proposal = paddle.concat((grid, wh), -1).reshape([N, -1, 4])
            proposals.append(proposal)
            _cur += H * W
        output_proposals = paddle.concat(proposals, 1)
        output_proposals_valid = (
            ((output_proposals > 0.01) & (output_proposals < 0.99))
            .all(-1, keepdim=True)
        )
        output_proposals = paddle.log(output_proposals / (1 - output_proposals))
        output_proposals = output_proposals.masked_fill(
            ~memory_padding_mask.astype('bool').unsqueeze(-1), float("inf"))
        output_proposals = output_proposals.masked_fill(
            ~output_proposals_valid, float("inf")
        )

        output_memory = memory
        output_memory = output_memory.masked_fill(
            ~memory_padding_mask.astype('bool').unsqueeze(-1), float(0))
        output_memory = output_memory.masked_fill(~output_proposals_valid, float(0))
        output_memory = self.enc_output_norm(self.enc_output(output_memory))
        return output_memory, output_proposals
Generate proposals from encoded memory.

        Args:
            memory (Tensor): The output of encoder, has shape
                (bs, num_key, embed_dim). num_key is equal the number of points
                on feature map from all level.
            memory_padding_mask (Tensor): Padding mask for memory.
                has shape (bs, num_key).
            spatial_shapes (Tensor): The shape of all feature maps.
                has shape (num_level, 2).

        Returns:
            tuple: A tuple of feature map and bbox prediction.

                - output_memory (Tensor): The input of decoder, has shape
                    (bs, num_key, embed_dim). num_key is equal the number of
                    points on feature map from all levels.
                - output_proposals (Tensor): The normalized proposal
                    after a inverse sigmoid, has shape (bs, num_keys, 4).
        
ppdet/modeling/transformers/co_deformable_detr_transformer.py