class_docstr: Decoder of DETR.
  
  Args:
      num_layers (int): Number of decoder layers.
      layer_cfg (:obj:`ConfigDict` or dict): the config of each encoder
          layer. All the layers will share the same config.
      post_norm_cfg (:obj:`ConfigDict` or dict, optional): Config of the
          post normalization layer. Defaults to `LN`.
      return_intermediate (bool, optional): Whether to return outputs of
          intermediate layers. Defaults to `True`,
      init_cfg (:obj:`ConfigDict` or dict, optional): the config to control
          the initialization. Defaults to None.
class_docstr_tok: ["Decoder","of","DETR",".","Args",":","num_layers","(","int",")",":","Number","of","decoder","layers",".","layer_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","the","config","of","each","encoder","layer",".","All","the","layers","will","share","the","same","config",".","post_norm_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","of","the","post","normalization","layer",".","Defaults","to","`","LN","`",".","return_intermediate","(","bool",",","optional",")",":","Whether","to","return","outputs","of","intermediate","layers",".","Defaults","to","`","True","`",",","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","the","config","to","control","the","initialization",".","Defaults","to","None","."]
docstr: Forward function of decoder
  Args:
      query (Tensor): The input query, has shape (bs, num_queries, dim).
      key (Tensor): The input key, has shape (bs, num_keys, dim).
      value (Tensor): The input value with the same shape as `key`.
      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`.
      key_padding_mask (Tensor): The `key_padding_mask` of `cross_attn`
          input. ByteTensor, has shape (bs, num_value).
  
  Returns:
      Tensor: The forwarded results will have shape
      (num_decoder_layers, bs, num_queries, dim) if
      `return_intermediate` is `True` else (1, bs, num_queries, dim).
docstr_tok: ["Forward","function","of","decoder","Args",":","query","(","Tensor",")",":","The","input","query",",","has","shape","(","bs",",","num_queries",",","dim",")",".","key","(","Tensor",")",":","The","input","key",",","has","shape","(","bs",",","num_keys",",","dim",")",".","value","(","Tensor",")",":","The","input","value","with","the","same","shape","as","`","key","`",".","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","`",".","key_padding_mask","(","Tensor",")",":","The","`","key_padding_mask","`","of","`","cross_attn","`","input",".","ByteTensor",",","has","shape","(","bs",",","num_value",")",".","Returns",":","Tensor",":","The","forwarded","results","will","have","shape","(","num_decoder_layers",",","bs",",","num_queries",",","dim",")","if","`","return_intermediate","`","is","`","True","`","else","(","1",",","bs",",","num_queries",",","dim",")","."]
code: def forward(
      self,
      query: Tensor,
      key: Tensor,
      value: Tensor,
      query_pos: Tensor,
      key_pos: Tensor,
      key_padding_mask: Tensor,
      **kwargs,
  ) -> Tensor:
      """Forward function of decoder
      Args:
          query (Tensor): The input query, has shape (bs, num_queries, dim).
          key (Tensor): The input key, has shape (bs, num_keys, dim).
          value (Tensor): The input value with the same shape as `key`.
          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`.
          key_padding_mask (Tensor): The `key_padding_mask` of `cross_attn`
              input. ByteTensor, has shape (bs, num_value).
  
      Returns:
          Tensor: The forwarded results will have shape
          (num_decoder_layers, bs, num_queries, dim) if
          `return_intermediate` is `True` else (1, bs, num_queries, dim).
      """
      intermediate = []
      for layer in self.layers:
          query = layer(
              query,
              key=key,
              value=value,
              query_pos=query_pos,
              key_pos=key_pos,
              key_padding_mask=key_padding_mask,
              **kwargs,
          )
          if self.return_intermediate:
              intermediate.append(self.post_norm(query))
      query = self.post_norm(query)
  
      if self.return_intermediate:
          return torch.stack(intermediate)
  
      return query.unsqueeze(0)
  
imports: from typing import Union
  import torch
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN, MultiheadAttention
  from mmengine import ConfigDict
  from mmengine.model import BaseModule, ModuleList
  from torch import Tensor
  from mmdet.utils import ConfigType, OptConfigType
label_desc: Use image node_id 3 for calling the DetrTransformerDecoder obj's underlying member method code with example usage: obj.forward(query, key, value, query_pos, key_pos, key_padding_mask) and returns: query, torch