class_docstr: Decoder of Conditional DETR.
class_docstr_tok: ["Decoder","of","Conditional","DETR","."]
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) If
          `None`, the `query` will be used. Defaults to `None`.
      query_pos (Tensor): The positional encoding for `query`, with the
          same shape as `query`. If not `None`, it will be added to
          `query` before forward function. Defaults to `None`.
      key_pos (Tensor): The positional encoding for `key`, with the
          same shape as `key`. If not `None`, it will be added to
          `key` before forward function. If `None`, and `query_pos`
          has the same shape as `key`, then `query_pos` will be used
          as `key_pos`. Defaults to `None`.
      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
      (bs, num_queries, 2).
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",")","If","`","None","`",",","the","`","query","`","will","be","used",".","Defaults","to","`","None","`",".","query_pos","(","Tensor",")",":","The","positional","encoding","for","`","query","`",",","with","the","same","shape","as","`","query","`",".","If","not","`","None","`",",","it","will","be","added","to","`","query","`","before","forward","function",".","Defaults","to","`","None","`",".","key_pos","(","Tensor",")",":","The","positional","encoding","for","`","key","`",",","with","the","same","shape","as","`","key","`",".","If","not","`","None","`",",","it","will","be","added","to","`","key","`","before","forward","function",".","If","`","None","`",",","and","`","query_pos","`","has","the","same","shape","as","`","key","`",",","then","`","query_pos","`","will","be","used","as","`","key_pos","`",".","Defaults","to","`","None","`",".","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","(","bs",",","num_queries",",","2",")","."]
code: def forward(
      self,
      query: Tensor,
      key: Tensor = None,
      query_pos: Tensor = None,
      key_pos: Tensor = None,
      key_padding_mask: Tensor = None,
  ):
      """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) If
              `None`, the `query` will be used. Defaults to `None`.
          query_pos (Tensor): The positional encoding for `query`, with the
              same shape as `query`. If not `None`, it will be added to
              `query` before forward function. Defaults to `None`.
          key_pos (Tensor): The positional encoding for `key`, with the
              same shape as `key`. If not `None`, it will be added to
              `key` before forward function. If `None`, and `query_pos`
              has the same shape as `key`, then `query_pos` will be used
              as `key_pos`. Defaults to `None`.
          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
          (bs, num_queries, 2).
      """
      reference_unsigmoid = self.ref_point_head(
          query_pos
      )  # [bs, num_queries, 2]
      reference = reference_unsigmoid.sigmoid()
      reference_xy = reference[..., :2]
      intermediate = []
      for layer_id, layer in enumerate(self.layers):
          if layer_id == 0:
              pos_transformation = 1
          else:
              pos_transformation = self.query_scale(query)
          # get sine embedding for the query reference
          ref_sine_embed = coordinate_to_encoding(
              coord_tensor=reference_xy
          )
          # apply transformation
          ref_sine_embed = ref_sine_embed * pos_transformation
          query = layer(
              query,
              key=key,
              query_pos=query_pos,
              key_pos=key_pos,
              key_padding_mask=key_padding_mask,
              ref_sine_embed=ref_sine_embed,
              is_first=(layer_id == 0),
          )
          if self.return_intermediate:
              intermediate.append(self.post_norm(query))
  
      if self.return_intermediate:
          return torch.stack(intermediate), reference
  
      query = self.post_norm(query)
      return query.unsqueeze(0), reference
  
file_path: mmdetection/mmdet/models/layers/transformer/conditional_detr_layers.py
imports: import torch
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN
  from torch import Tensor
  from torch.nn import ModuleList
  from .detr_layers import DetrTransformerDecoder, DetrTransformerDecoderLayer
  from .utils import MLP, ConditionalAttention, coordinate_to_encoding
label_desc: Use image node_id 2 for calling the ConditionalDetrTransformerDecoder obj's underlying member method code with example usage: obj.forward(query, key, query_pos, key_pos, key_padding_mask) and returns: query,  reference, torch,  reference