class_docstr: Implements the decoder in DETR transformer.
  
  Args:
      return_intermediate (bool): Whether to return intermediate outputs.
      coder_norm_cfg (dict): Config of last normalization layer. Default：
          `LN`.
class_docstr_tok: ["Implements","the","decoder","in","DETR","transformer",".","Args",":","return_intermediate","(","bool",")",":","Whether","to","return","intermediate","outputs",".","coder_norm_cfg","(","dict",")",":","Config","of","last","normalization","layer",".","Default\uff1a","`","LN","`","."]
docstr: Forward function for `TransformerDecoder`.
  
  Args:
      query (Tensor): Input query with shape
          `(num_query, bs, embed_dims)`.
      reference_points (Tensor): The reference
          points of offset. has shape
          (bs, num_query, 4) when as_two_stage,
          otherwise has shape ((bs, num_query, 2).
      valid_ratios (Tensor): The radios of valid
          points on the feature map, has shape
          (bs, num_levels, 2)
      reg_branch: (obj:`nn.ModuleList`): Used for
          refining the regression results. Only would
          be passed when with_box_refine is True,
          otherwise would be passed a `None`.
  
  Returns:
      Tensor: Results with shape [1, num_query, bs, embed_dims] when
          return_intermediate is `False`, otherwise it has shape
          [num_layers, num_query, bs, embed_dims].
code: def forward(
      self,
      query,
      *args,
      reference_points=None,
      valid_ratios=None,
      reg_branches=None,
      **kwargs,
  ):
      """Forward function for `TransformerDecoder`.
  
      Args:
          query (Tensor): Input query with shape
              `(num_query, bs, embed_dims)`.
          reference_points (Tensor): The reference
              points of offset. has shape
              (bs, num_query, 4) when as_two_stage,
              otherwise has shape ((bs, num_query, 2).
          valid_ratios (Tensor): The radios of valid
              points on the feature map, has shape
              (bs, num_levels, 2)
          reg_branch: (obj:`nn.ModuleList`): Used for
              refining the regression results. Only would
              be passed when with_box_refine is True,
              otherwise would be passed a `None`.
  
      Returns:
          Tensor: Results with shape [1, num_query, bs, embed_dims] when
              return_intermediate is `False`, otherwise it has shape
              [num_layers, num_query, bs, embed_dims].
      """
      output = query
      intermediate = []
      intermediate_reference_points = []
      for lid, layer in enumerate(self.layers):
          if reference_points.shape[-1] == 4:
              reference_points_input = (
                  reference_points[:, :, None]
                  * torch.cat([valid_ratios, valid_ratios], -1)[:, None]
              )
          else:
              assert reference_points.shape[-1] == 2
              reference_points_input = (
                  reference_points[:, :, None] * valid_ratios[:, None]
              )
          output = layer(
              output,
              *args,
              reference_points=reference_points_input,
              **kwargs,
          )
          output = output.permute(1, 0, 2)
  
          if reg_branches is not None:
              tmp = reg_branches[lid](output)
              if reference_points.shape[-1] == 4:
                  new_reference_points = tmp + inverse_sigmoid(
                      reference_points
                  )
                  new_reference_points = new_reference_points.sigmoid()
              else:
                  assert reference_points.shape[-1] == 2
                  new_reference_points = tmp
                  new_reference_points[..., :2] = tmp[
                      ..., :2
                  ] + inverse_sigmoid(reference_points)
                  new_reference_points = new_reference_points.sigmoid()
              reference_points = new_reference_points.detach()
  
          output = output.permute(1, 0, 2)
          if self.return_intermediate:
              intermediate.append(output)
              intermediate_reference_points.append(
                  new_reference_points
                  if self.look_forward_twice
                  else reference_points
              )
      if self.return_intermediate:
          return torch.stack(intermediate), torch.stack(
              intermediate_reference_points
          )
  
      return output, reference_points
  
imports: import math
  import warnings
  import torch
  import torch.nn
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import BaseTransformerLayer, TransformerLayerSequence, build_transformer_layer_sequence
  from mmcv.ops import MultiScaleDeformableAttention
  from mmengine.model import BaseModule
  from mmengine.model.weight_init import xavier_init
  from torch.nn.init import normal_
  from mmdet.models.layers.transformer import inverse_sigmoid
  from mmdet.registry import MODELS
label_desc: Use image node_id 2 for calling the CoDeformableDetrTransformerDecoder obj's underlying member method code with example usage: obj.forward(query) and returns: output,  reference_points, torch,  torch