class_docstr: Decoder of DAB-DETR.
  
  Args:
      query_dim (int): The last dimension of query pos,
          4 for anchor format, 2 for point format.
          Defaults to 4.
      query_scale_type (str): Type of transformation applied
          to content query. Defaults to `cond_elewise`.
      with_modulated_hw_attn (bool): Whether to inject h&w info
          during cross conditional attention. Defaults to True.
docstr: Forward function of decoder.
  
  Args:
      query (Tensor): The input query with shape (bs, num_queries, dim).
      key (Tensor): The input key with shape (bs, num_keys, dim).
      query_pos (Tensor): The positional encoding for `query`, with the
          same shape as `query`.
      key_pos (Tensor): The positional encoding for `key`, with the
          same shape as `key`.
      reg_branches (nn.Module): The regression branch for dynamically
          updating references in each layer.
      key_padding_mask (Tensor): ByteTensor with shape (bs, num_keys).
          Defaults to `None`.
  
  Returns:
      List[Tensor]: forwarded results with shape (num_decoder_layers,
      bs, num_queries, dim) if `return_intermediate` is True, otherwise
      with shape (1, bs, num_queries, dim). references with shape
      (num_decoder_layers, bs, num_queries, 2/4).
docstr_tok: ["Forward","function","of","decoder",".","Args",":","query","(","Tensor",")",":","The","input","query","with","shape","(","bs",",","num_queries",",","dim",")",".","key","(","Tensor",")",":","The","input","key","with","shape","(","bs",",","num_keys",",","dim",")",".","query_pos","(","Tensor",")",":","The","positional","encoding","for","`","query","`",",","with","the","same","shape","as","`","query","`",".","key_pos","(","Tensor",")",":","The","positional","encoding","for","`","key","`",",","with","the","same","shape","as","`","key","`",".","reg_branches","(","nn.Module",")",":","The","regression","branch","for","dynamically","updating","references","in","each","layer",".","key_padding_mask","(","Tensor",")",":","ByteTensor","with","shape","(","bs",",","num_keys",")",".","Defaults","to","`","None","`",".","Returns",":","List","[","Tensor","]",":","forwarded","results","with","shape","(","num_decoder_layers",",","bs",",","num_queries",",","dim",")","if","`","return_intermediate","`","is","True",",","otherwise","with","shape","(","1",",","bs",",","num_queries",",","dim",")",".","references","with","shape","(","num_decoder_layers",",","bs",",","num_queries",",","2\/4",")","."]
code: def forward(
      self,
      query: Tensor,
      key: Tensor,
      query_pos: Tensor,
      key_pos: Tensor,
      reg_branches: nn.Module,
      key_padding_mask: Tensor = None,
      **kwargs,
  ) -> List[Tensor]:
      """Forward function of decoder.
  
      Args:
          query (Tensor): The input query with shape (bs, num_queries, dim).
          key (Tensor): The input key with shape (bs, num_keys, dim).
          query_pos (Tensor): The positional encoding for `query`, with the
              same shape as `query`.
          key_pos (Tensor): The positional encoding for `key`, with the
              same shape as `key`.
          reg_branches (nn.Module): The regression branch for dynamically
              updating references in each layer.
          key_padding_mask (Tensor): ByteTensor with shape (bs, num_keys).
              Defaults to `None`.
  
      Returns:
          List[Tensor]: forwarded results with shape (num_decoder_layers,
          bs, num_queries, dim) if `return_intermediate` is True, otherwise
          with shape (1, bs, num_queries, dim). references with shape
          (num_decoder_layers, bs, num_queries, 2/4).
      """
      output = query
      unsigmoid_references = query_pos
  
      reference_points = unsigmoid_references.sigmoid()
      intermediate_reference_points = [reference_points]
  
      intermediate = []
      for layer_id, layer in enumerate(self.layers):
          obj_center = reference_points[..., : self.query_dim]
          ref_sine_embed = coordinate_to_encoding(
              coord_tensor=obj_center, num_feats=self.embed_dims // 2
          )
          query_pos = self.ref_point_head(
              ref_sine_embed
          )  # [bs, nq, 2c] -> [bs, nq, c]
          # For the first decoder layer, do not apply transformation
          if self.query_scale_type != "fix_elewise":
              if layer_id == 0:
                  pos_transformation = 1
              else:
                  pos_transformation = self.query_scale(output)
          else:
              pos_transformation = self.query_scale.weight[layer_id]
          # apply transformation
          ref_sine_embed = (
              ref_sine_embed[..., : self.embed_dims]
              * pos_transformation
          )
          # modulated height and weight attention
          if self.with_modulated_hw_attn:
              assert obj_center.size(-1) == 4
              ref_hw = self.ref_anchor_head(output).sigmoid()
              ref_sine_embed[..., self.embed_dims // 2 :] *= (
                  ref_hw[..., 0] / obj_center[..., 2]
              ).unsqueeze(-1)
              ref_sine_embed[..., : self.embed_dims // 2] *= (
                  ref_hw[..., 1] / obj_center[..., 3]
              ).unsqueeze(-1)
  
          output = layer(
              output,
              key,
              query_pos=query_pos,
              ref_sine_embed=ref_sine_embed,
              key_pos=key_pos,
              key_padding_mask=key_padding_mask,
              is_first=(layer_id == 0),
              **kwargs,
          )
          # iter update
          tmp_reg_preds = reg_branches(output)
          tmp_reg_preds[..., : self.query_dim] += inverse_sigmoid(
              reference_points
          )
          new_reference_points = tmp_reg_preds[
              ..., : self.query_dim
          ].sigmoid()
          if layer_id != self.num_layers - 1:
              intermediate_reference_points.append(new_reference_points)
          reference_points = new_reference_points.detach()
  
          if self.return_intermediate:
              intermediate.append(self.post_norm(output))
  
      output = self.post_norm(output)
  
      if self.return_intermediate:
          return [
              torch.stack(intermediate),
              torch.stack(intermediate_reference_points),
          ]
      else:
          return [
              output.unsqueeze(0),
              torch.stack(intermediate_reference_points),
          ]
  
imports: from typing import List
  import torch
  import torch.nn
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN
  from mmengine.model import ModuleList
  from torch import Tensor
  from .detr_layers import DetrTransformerDecoder, DetrTransformerDecoderLayer, DetrTransformerEncoder, DetrTransformerEncoderLayer
  from .utils import MLP, ConditionalAttention, coordinate_to_encoding, inverse_sigmoid
label_desc: Use image node_id 3 for calling the DABDetrTransformerDecoder obj's underlying member method code with example usage: obj.forward(query, key, query_pos, key_pos, reg_branches, key_padding_mask) and returns: list, list