class_docstr: CoFormer model for Grounded Situation Recognition
  Args:
      backbone (`nn.Module`):
          Torch module of the backbone to be used. See backbone.py.
      transformer (`nn.Module`):
          Torch module of the transformer architecture. See transformer.py.
      num_noun_classes (`int`):
          The number of noun classes.
      vidx_ridx (`dict`):
          Verb index to role index.
class_docstr_tok: ["CoFormer","model","for","Grounded","Situation","Recognition","Args",":","backbone","(","`","nn.Module","`",")",":","Torch","module","of","the","backbone","to","be","used",".","See","backbone.py",".","transformer","(","`","nn.Module","`",")",":","Torch","module","of","the","transformer","architecture",".","See","transformer.py",".","num_noun_classes","(","`","int","`",")",":","The","number","of","noun","classes",".","vidx_ridx","(","`","dict","`",")",":","Verb","index","to","role","index","."]
code: def __init__(
      self,
      backbone: nn.Module,
      transformer: nn.Module,
      num_noun_classes: int,
      vidx_ridx: dict,
  ):
      super().__init__()
      self.backbone = backbone
      self.transformer = transformer
      self.num_noun_classes = num_noun_classes
      self.vidx_ridx = vidx_ridx
      self.num_role_tokens = 190
      self.num_verb_tokens = 504
  
      # hidden dimension for tokens and image features
      hidden_dim = transformer.d_model
  
      # token embeddings
      self.role_token_embed = nn.Embedding(
          self.num_role_tokens, hidden_dim
      )
      self.verb_token_embed = nn.Embedding(
          self.num_verb_tokens, hidden_dim
      )
      self.il_token_embed = nn.Embedding(1, hidden_dim)
      self.rl_token_embed = nn.Embedding(1, hidden_dim)
  
      # 1x1 Conv
      self.input_proj = nn.Conv2d(
          backbone.num_channels, hidden_dim, kernel_size=1
      )
  
      # classifiers & predictors (for grounded noun prediction)
      self.noun_1_classifier = nn.Linear(
          hidden_dim, self.num_noun_classes
      )
      self.noun_2_classifier = nn.Linear(
          hidden_dim, self.num_noun_classes
      )
      self.noun_3_classifier = nn.Sequential(
          nn.Linear(hidden_dim, hidden_dim * 2),
          nn.ReLU(),
          nn.Dropout(0.3),
          nn.Linear(hidden_dim * 2, self.num_noun_classes),
      )
      self.bbox_predictor = nn.Sequential(
          nn.Linear(hidden_dim, hidden_dim * 2),
          nn.ReLU(),
          nn.Dropout(0.2),
          nn.Linear(hidden_dim * 2, hidden_dim * 2),
          nn.ReLU(),
          nn.Dropout(0.2),
          nn.Linear(hidden_dim * 2, 4),
      )
      self.bbox_conf_predictor = nn.Sequential(
          nn.Linear(hidden_dim, hidden_dim * 2),
          nn.ReLU(),
          nn.Dropout(0.2),
          nn.Linear(hidden_dim * 2, 1),
      )
  
      # layer norms
      self.ln1 = nn.LayerNorm(hidden_dim)
      self.ln2 = nn.LayerNorm(hidden_dim)
  
file_path: towhee/towhee/models/coformer/coformer.py
imports: import torch
  import torch.nn.functional
  from typing import Any
  from torch import nn
  from towhee.models.coformer.utils import nested_tensor_from_tensor_list
  from towhee.models.coformer.backbone import build_backbone
  from towhee.models.coformer.transformer import build_transformer
  from towhee.models.coformer.config import _C
label_desc: Use image node_id 1 to create a new CoFormer object from inherited base classes: nn with example: obj = CoFormer(backbone, transformer, num_noun_classes, vidx_ridx)