class_docstr: Head of the Grounding DINO: Marrying DINO with Grounded Pre-Training for
  Open-Set Object Detection.
  
  Args:
      contrastive_cfg (dict, optional): Contrastive config that contains
        keys like ``max_text_len``. Defaults to dict(max_text_len=256).
class_docstr_tok: ["Head","of","the","Grounding","DINO",":","Marrying","DINO","with","Grounded","Pre-Training","for","Open-Set","Object","Detection",".","Args",":","contrastive_cfg","(","dict",",","optional",")",":","Contrastive","config","that","contains","keys","like","``","max_text_len","``",".","Defaults","to","dict","(","max_text_len=256",")","."]
docstr: Initialize classification branch and regression branch of head.
docstr_tok: ["Initialize","classification","branch","and","regression","branch","of","head","."]
code: def _init_layers(self) -> None:
      """Initialize classification branch and regression branch of head."""
      fc_cls = ContrastiveEmbed(**self.contrastive_cfg)
      reg_branch = []
      for _ in range(self.num_reg_fcs):
          reg_branch.append(Linear(self.embed_dims, self.embed_dims))
          reg_branch.append(nn.ReLU())
      reg_branch.append(Linear(self.embed_dims, 4))
      reg_branch = nn.Sequential(*reg_branch)
  
      # NOTE: due to the fc_cls is a contrastive embedding and don't
      # have any trainable parameters,we do not need to copy it.
      if self.share_pred_layer:
          self.cls_branches = nn.ModuleList(
              [fc_cls for _ in range(self.num_pred_layer)]
          )
          self.reg_branches = nn.ModuleList(
              [reg_branch for _ in range(self.num_pred_layer)]
          )
      else:
          self.cls_branches = nn.ModuleList(
              [
                  copy.deepcopy(fc_cls)
                  for _ in range(self.num_pred_layer)
              ]
          )
          self.reg_branches = nn.ModuleList(
              [
                  copy.deepcopy(reg_branch)
                  for _ in range(self.num_pred_layer)
              ]
          )
  
imports: import copy
  import math
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  import torch.nn
  from mmcv.cnn import Linear
  from mmengine.model import constant_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.losses import QualityFocalLoss
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy, bbox_xyxy_to_cxcywh
  from mmdet.utils import InstanceList, reduce_mean
  from ..layers import inverse_sigmoid
  from .atss_vlfusion_head import convert_grounding_to_cls_scores
  from .dino_head import DINOHead
label_desc: Use image node_id 2 for calling the GroundingDINOHead obj's underlying member method code with example usage: obj._init_layers() without return types