class_docstr: TransChex based on: "Hatamizadeh et al.,TransCheX: Self-Supervised Pretraining of Vision-Language
  Transformers for Chest X-ray Analysis"
docstr: Args:
      in_channels: dimension of input channels.
      img_size: dimension of input image.
      patch_size: dimension of patch size.
      num_classes: number of classes if classification is used.
      num_language_layers: number of language transformer layers.
      num_vision_layers: number of vision transformer layers.
      num_mixed_layers: number of mixed transformer layers.
      drop_out: fraction of the input units to drop.
      path_or_repo_id: This can be either:
          - a string, the *model id* of a model repo on huggingface.co.
          - a path to a *directory* potentially containing the file.
      filename: The name of the file to locate in `path_or_repo`.
  
  The other parameters are part of the `bert_config` to `MultiModal.from_pretrained`.
  
  Examples:
  
  .. code-block:: python
  
      # for 3-channel with image size of (224,224), patch size of (32,32), 3 classes, 2 language layers,
      # 2 vision layers, 2 mixed modality layers and dropout of 0.2 in the classification head
      net = Transchex(in_channels=3,
                           img_size=(224, 224),
                           num_classes=3,
                           num_language_layers=2,
                           num_vision_layers=2,
                           num_mixed_layers=2,
                           drop_out=0.2)
docstr_tok: ["Args",":","in_channels",":","dimension","of","input","channels",".","img_size",":","dimension","of","input","image",".","patch_size",":","dimension","of","patch","size",".","num_classes",":","number","of","classes","if","classification","is","used",".","num_language_layers",":","number","of","language","transformer","layers",".","num_vision_layers",":","number","of","vision","transformer","layers",".","num_mixed_layers",":","number","of","mixed","transformer","layers",".","drop_out",":","fraction","of","the","input","units","to","drop",".","path_or_repo_id",":","This","can","be","either",":","-","a","string",",","the","*","model","id","*","of","a","model","repo","on","huggingface.co",".","-","a","path","to","a","*","directory","*","potentially","containing","the","file",".","filename",":","The","name","of","the","file","to","locate","in","`","path_or_repo","`",".","The","other","parameters","are","part","of","the","`","bert_config","`","to","`","MultiModal.from_pretrained","`",".","Examples",":","..","code-block",":",":","python","#","for","3-channel","with","image","size","of","(","224,224",")",",","patch","size","of","(","32,32",")",",","3","classes",",","2","language","layers",",","#","2","vision","layers",",","2","mixed","modality","layers","and","dropout","of","0.2","in","the","classification","head","net","=","Transchex","(","in_channels=3",",","img_size=","(","224",",","224",")",",","num_classes=3",",","num_language_layers=2",",","num_vision_layers=2",",","num_mixed_layers=2",",","drop_out=0.2",")"]
code: def __init__(
      self,
      in_channels: int,
      img_size: Sequence[int] | int,
      patch_size: int | tuple[int, int],
      num_classes: int,
      num_language_layers: int,
      num_vision_layers: int,
      num_mixed_layers: int,
      hidden_size: int = 768,
      drop_out: float = 0.0,
      attention_probs_dropout_prob: float = 0.1,
      gradient_checkpointing: bool = False,
      hidden_act: str = "gelu",
      hidden_dropout_prob: float = 0.1,
      initializer_range: float = 0.02,
      intermediate_size: int = 3072,
      layer_norm_eps: float = 1e-12,
      max_position_embeddings: int = 512,
      model_type: str = "bert",
      num_attention_heads: int = 12,
      num_hidden_layers: int = 12,
      pad_token_id: int = 0,
      position_embedding_type: str = "absolute",
      transformers_version: str = "4.10.2",
      type_vocab_size: int = 2,
      use_cache: bool = True,
      vocab_size: int = 30522,
      chunk_size_feed_forward: int = 0,
      is_decoder: bool = False,
      add_cross_attention: bool = False,
      path_or_repo_id: str | PathLike = "bert-base-uncased",
      filename: str = "pytorch_model.bin",
  ) -> None:
      """
      Args:
          in_channels: dimension of input channels.
          img_size: dimension of input image.
          patch_size: dimension of patch size.
          num_classes: number of classes if classification is used.
          num_language_layers: number of language transformer layers.
          num_vision_layers: number of vision transformer layers.
          num_mixed_layers: number of mixed transformer layers.
          drop_out: fraction of the input units to drop.
          path_or_repo_id: This can be either:
              - a string, the *model id* of a model repo on huggingface.co.
              - a path to a *directory* potentially containing the file.
          filename: The name of the file to locate in `path_or_repo`.
  
      The other parameters are part of the `bert_config` to `MultiModal.from_pretrained`.
  
      Examples:
  
      .. code-block:: python
  
          # for 3-channel with image size of (224,224), patch size of (32,32), 3 classes, 2 language layers,
          # 2 vision layers, 2 mixed modality layers and dropout of 0.2 in the classification head
          net = Transchex(in_channels=3,
                               img_size=(224, 224),
                               num_classes=3,
                               num_language_layers=2,
                               num_vision_layers=2,
                               num_mixed_layers=2,
                               drop_out=0.2)
  
      """
      super().__init__()
      bert_config = {
          "attention_probs_dropout_prob": attention_probs_dropout_prob,
          "classifier_dropout": None,
          "gradient_checkpointing": gradient_checkpointing,
          "hidden_act": hidden_act,
          "hidden_dropout_prob": hidden_dropout_prob,
          "hidden_size": hidden_size,
          "initializer_range": initializer_range,
          "intermediate_size": intermediate_size,
          "layer_norm_eps": layer_norm_eps,
          "max_position_embeddings": max_position_embeddings,
          "model_type": model_type,
          "num_attention_heads": num_attention_heads,
          "num_hidden_layers": num_hidden_layers,
          "pad_token_id": pad_token_id,
          "position_embedding_type": position_embedding_type,
          "transformers_version": transformers_version,
          "type_vocab_size": type_vocab_size,
          "use_cache": use_cache,
          "vocab_size": vocab_size,
          "chunk_size_feed_forward": chunk_size_feed_forward,
          "is_decoder": is_decoder,
          "add_cross_attention": add_cross_attention,
      }
      if not (0 <= drop_out <= 1):
          raise ValueError("dropout_rate should be between 0 and 1.")
  
      if (img_size[0] % patch_size[0] != 0) or (img_size[1] % patch_size[1] != 0):  # type: ignore
          raise ValueError(
              "img_size should be divisible by patch_size."
          )
  
      self.multimodal = MultiModal.from_pretrained(
          num_language_layers=num_language_layers,
          num_vision_layers=num_vision_layers,
          num_mixed_layers=num_mixed_layers,
          bert_config=bert_config,
          path_or_repo_id=path_or_repo_id,
          filename=filename,
      )
  
      self.patch_size = patch_size
      self.num_patches = (img_size[0] // self.patch_size[0]) * (img_size[1] // self.patch_size[1])  # type: ignore
      self.vision_proj = nn.Conv2d(
          in_channels=in_channels,
          out_channels=hidden_size,
          kernel_size=self.patch_size,
          stride=self.patch_size,
      )
      self.norm_vision_pos = nn.LayerNorm(hidden_size)
      self.pos_embed_vis = nn.Parameter(
          torch.zeros(1, self.num_patches, hidden_size)
      )
      self.pooler = Pooler(hidden_size=hidden_size)
      self.drop = torch.nn.Dropout(drop_out)
      self.cls_head = torch.nn.Linear(hidden_size, num_classes)
  
imports: from __future__ import annotations
  import math
  from collections.abc import Sequence
  import torch
  from torch import nn
  from monai.config.type_definitions import PathLike
  from monai.utils import optional_import
label_desc: Use image node_id 1 to create a new Transchex object from inherited base classes: torch.nn with example: obj = Transchex(in_channels, img_size, patch_size, num_classes, num_language_layers, num_vision_layers, num_mixed_layers, hidden_size, drop_out, attention_probs_dropout_prob, gradient_checkpointing, hidden_act, hidden_dropout_prob, initializer_range, intermediate_size, layer_norm_eps, max_position_embeddings, model_type, num_attention_heads, num_hidden_layers, pad_token_id, position_embedding_type, transformers_version, type_vocab_size, use_cache, vocab_size, chunk_size_feed_forward, is_decoder, add_cross_attention, path_or_repo_id, filename)