class_docstr: Implementation of `DAB-DETR:
  Dynamic Anchor Boxes are Better Queries for DETR.
  
  <https://arxiv.org/abs/2201.12329>`_.
  
  Code is modified from the `official github repo
  <https://github.com/IDEA-Research/DAB-DETR>`_.
  
  Args:
      with_random_refpoints (bool): Whether to randomly initialize query
          embeddings and not update them during training.
          Defaults to False.
      num_patterns (int): Inspired by Anchor-DETR. Defaults to 0.
class_docstr_tok: ["Implementation","of","`","DAB-DETR",":","Dynamic","Anchor","Boxes","are","Better","Queries","for","DETR",".","<","https",":","\/\/arxiv.org\/abs\/2201.12329",">","`","_",".","Code","is","modified","from","the","`","official","github","repo","<","https",":","\/\/github.com\/IDEA-Research\/DAB-DETR",">","`","_",".","Args",":","with_random_refpoints","(","bool",")",":","Whether","to","randomly","initialize","query","embeddings","and","not","update","them","during","training",".","Defaults","to","False",".","num_patterns","(","int",")",":","Inspired","by","Anchor-DETR",".","Defaults","to","0","."]
docstr: Prepare intermediate variables before entering Transformer decoder,
  such as `query`, `query_pos`.
  
  Args:
      memory (Tensor): The output embeddings of the Transformer encoder,
          has shape (bs, num_feat_points, dim).
  
  Returns:
      tuple[dict, dict]: The first dict contains the inputs of decoder
      and the second dict contains the inputs of the bbox_head function.
  
      - decoder_inputs_dict (dict): The keyword args dictionary of
          `self.forward_decoder()`, which includes 'query', 'query_pos',
          'memory' and 'reg_branches'.
      - head_inputs_dict (dict): The keyword args dictionary of the
          bbox_head functions, which is usually empty, or includes
          `enc_outputs_class` and `enc_outputs_class` when the detector
          support 'two stage' or 'query selection' strategies.
docstr_tok: ["Prepare","intermediate","variables","before","entering","Transformer","decoder",",","such","as","`","query","`",",","`","query_pos","`",".","Args",":","memory","(","Tensor",")",":","The","output","embeddings","of","the","Transformer","encoder",",","has","shape","(","bs",",","num_feat_points",",","dim",")",".","Returns",":","tuple","[","dict",",","dict","]",":","The","first","dict","contains","the","inputs","of","decoder","and","the","second","dict","contains","the","inputs","of","the","bbox_head","function",".","-","decoder_inputs_dict","(","dict",")",":","The","keyword","args","dictionary","of","`","self.forward_decoder","(",")","`",",","which","includes","'query","'",",","'query_pos","'",",","'memory","'","and","'reg_branches","'",".","-","head_inputs_dict","(","dict",")",":","The","keyword","args","dictionary","of","the","bbox_head","functions",",","which","is","usually","empty",",","or","includes","`","enc_outputs_class","`","and","`","enc_outputs_class","`","when","the","detector","support","'two","stage","'","or","'query","selection","'","strategies","."]
code: def pre_decoder(self, memory: Tensor) -> Tuple[Dict, Dict]:
      """Prepare intermediate variables before entering Transformer decoder,
      such as `query`, `query_pos`.
  
      Args:
          memory (Tensor): The output embeddings of the Transformer encoder,
              has shape (bs, num_feat_points, dim).
  
      Returns:
          tuple[dict, dict]: The first dict contains the inputs of decoder
          and the second dict contains the inputs of the bbox_head function.
  
          - decoder_inputs_dict (dict): The keyword args dictionary of
              `self.forward_decoder()`, which includes 'query', 'query_pos',
              'memory' and 'reg_branches'.
          - head_inputs_dict (dict): The keyword args dictionary of the
              bbox_head functions, which is usually empty, or includes
              `enc_outputs_class` and `enc_outputs_class` when the detector
              support 'two stage' or 'query selection' strategies.
      """
      batch_size = memory.size(0)
      query_pos = self.query_embedding.weight
      query_pos = query_pos.unsqueeze(0).repeat(batch_size, 1, 1)
      if self.num_patterns == 0:
          query = query_pos.new_zeros(
              batch_size, self.num_queries, self.embed_dims
          )
      else:
          query = (
              self.patterns.weight[:, None, None, :]
              .repeat(1, self.num_queries, batch_size, 1)
              .view(-1, batch_size, self.embed_dims)
              .permute(1, 0, 2)
          )
          query_pos = query_pos.repeat(1, self.num_patterns, 1)
  
      decoder_inputs_dict = dict(
          query_pos=query_pos, query=query, memory=memory
      )
      head_inputs_dict = dict()
      return decoder_inputs_dict, head_inputs_dict
  
file_path: mmdetection/mmdet/models/detectors/dab_detr.py
imports: from typing import Dict, Tuple
  from mmengine.model import uniform_init
  from torch import Tensor, nn
  from mmdet.registry import MODELS
  from ..layers import SinePositionalEncoding
  from ..layers.transformer import DABDetrTransformerDecoder, DABDetrTransformerEncoder, inverse_sigmoid
  from .detr import DETR
label_desc: Use image node_id 4 for calling the DABDETR obj's underlying member method code with example usage: obj.pre_decoder(memory) and returns: decoder_inputs_dict,  head_inputs_dict