class_docstr: This class implements a `Mask RCNN style object detector <https://arxiv.org/abs/1703.06870>`
  
  Args:
      opts: command-line arguments
      encoder (BaseImageEncoder): Encoder network (e.g., ResNet or MobileViT)
class_docstr_tok: ["This","class","implements","a","`","Mask","RCNN","style","object","detector","<","https",":","\/\/arxiv.org\/abs\/1703.06870",">","`","Args",":","opts",":","command-line","arguments","encoder","(","BaseImageEncoder",")",":","Encoder","network","(","e.g.",",","ResNet","or","MobileViT",")"]
docstr: Add model specific arguments
docstr_tok: ["Add","model","specific","arguments"]
code: def add_arguments(
      cls, parser: argparse.ArgumentParser
  ) -> argparse.ArgumentParser:
      """Add model specific arguments"""
      group = parser.add_argument_group(cls.__name__)
      group.add_argument(
          "--model.detection.mask-rcnn.backbone-projection-channels",
          type=int,
          default=256,
          help="Projection channels for the encoder in Mask-RCNN",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.backbone-lr-multiplier",
          type=float,
          default=1.0,
          help="LR multiplier for MASK RCNN head",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.output-strides",
          type=int,
          nargs="+",
          default=[4, 8, 16, 32, 64],
          help="Extract backbone feature maps from these output strides. "
          "If output stride is greater than 32, extra layers are added.",
      )
      group.add_argument(
          "--model.detection.mask-rcnn.anchor-sizes",
          type=int,
          nargs="+",
          action="append",
          default=[32, 64, 128, 256, 512],
          help="Anchor sizes at each output stride",
      )
      group.add_argument(
          "--model.detection.mask-rcnn.aspect-ratio",
          type=float,
          nargs="+",
          default=[0.5, 1.0, 2.0],
          help="Aspect ratios. These are the same for all feature maps",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.bbox-head-fm-size",
          type=int,
          default=7,
          help="Feature map size for the box head",
      )
      group.add_argument(
          "--model.detection.mask-rcnn.mask-head-fm-size",
          type=int,
          default=14,
          help="Feature map size for the max head",
      )
      group.add_argument(
          "--model.detection.mask-rcnn.representation-size",
          type=int,
          default=1024,
          help="Size of the intermediate representation in Mask RCNN",
      )
      # box_fm_size_conv_layer = getattr(opts, "", [256] * 4)
      group.add_argument(
          "--model.detection.mask-rcnn.box-fm-size-conv-layer",
          type=int,
          nargs="+",
          default=[256] * 4,
          help="Feature dim of each Convolution layer in the Faster RCNN head. Defaults to [256, 256, 256, 256]",
      )
      group.add_argument(
          "--model.detection.mask-rcnn.mask-fm-size-conv-layer",
          type=int,
          nargs="+",
          default=[256] * 4,
          help="Feature dim of each Convolution layer in the Mask RCNN head. Defaults to [256, 256, 256, 256]",
      )
      group.add_argument(
          "--model.detection.mask-rcnn.mask-dilation",
          type=int,
          default=1,
          help="Dilation rate in Mask RCNN head. Defaults to 1",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.rpn-pre-nms-top-n-train",
          type=int,
          default=2000,
          help="Number of proposals to keep before applying NMS during training",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.rpn-pre-nms-top-n-test",
          type=int,
          default=1000,
          help="Number of proposals to keep before applying NMS during test",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.rpn-post-nms-top-n-train",
          type=int,
          default=2000,
          help="Number of proposals to keep after applying NMS during training",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.rpn-post-nms-top-n-test",
          type=int,
          default=1000,
          help="Number of proposals to keep after applying NMS during test",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.rpn-nms-thresh",
          type=float,
          default=0.7,
          help="NMS threshold used for postprocessing the RPN proposals",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.rpn-fg-iou-thresh",
          type=float,
          default=0.7,
          help="minimum IoU between the anchor and the GT box so that they can be "
          "considered as positive during training of the RPN.",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.rpn-bg-iou-thresh",
          type=float,
          default=0.7,
          help="minimum IoU between the anchor and the GT box so that they can be "
          "considered as negative during training of the RPN.",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.rpn-batch-size-per-image",
          type=int,
          default=256,
          help="Number of anchors that are sampled during training of the RPN for computing the loss",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.rpn-positive-fraction",
          type=float,
          default=0.5,
          help="Proportion of positive anchors in a mini-batch during training of the RPN",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.rpn-score-thresh",
          type=float,
          default=0.0,
          help="During inference, only return proposals with a classification score greater than rpn_score_thresh",
      )
  
      #
      group.add_argument(
          "--model.detection.mask-rcnn.box-score-thresh",
          type=float,
          default=0.05,
          help="During inference, only return proposals with a classification score greater than box_score_thresh",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.box-nms-thresh",
          type=float,
          default=0.5,
          help="During inference, NMS threshold for the prediction head.",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.box-detections-per-img",
          type=int,
          default=100,
          help="Maximum number of detections per image, for all classes",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.box-fg-iou-thresh",
          type=float,
          default=0.5,
          help="Minimum IoU between the proposals and the GT box so that they can be considered as "
          "positive during training of the classification head",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.box-bg-iou-thresh",
          type=float,
          default=0.5,
          help="Minimum IoU between the proposals and the GT box so that they can be considered as "
          "negative during training of the classification head",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.box-batch-size-per-image",
          type=int,
          default=512,
          help="Number of proposals that are sampled during training of the classification head",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.box-positive-fraction",
          type=float,
          default=0.25,
          help="Proportion of positive proposals in a mini-batch during training of the classification head",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.norm-layer",
          type=str,
          default=None,
          help="Mask RCNN Norm layer",
      )
  
      group.add_argument(
          "--model.detection.mask-rcnn.disable-fpn",
          action="store_true",
          help="Do not use FPN",
      )
      return parser
  
imports: import argparse
  from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  from torch import Tensor, nn
  from torch.nn import functional
  from torchvision.models.detection.anchor_utils import AnchorGenerator
  from torchvision.models.detection.mask_rcnn import MaskRCNN
  from torchvision.ops import MultiScaleRoIAlign
  from cvnets import parameter_list
  from cvnets.layers import ConvLayer2d, Identity
  from cvnets.models import MODEL_REGISTRY
  from cvnets.models.classification.base_image_encoder import BaseImageEncoder
  from cvnets.models.detection import DetectionPredTuple
  from cvnets.models.detection.base_detection import BaseDetection
  from cvnets.models.detection.utils.rcnn_utils import FastRCNNConvFCHead, FastRCNNPredictor, MaskRCNNHeads, MaskRCNNPredictor, RPNHead
  from utils import logger
label_desc: Use image node_id 5 for calling the MaskRCNNDetector obj's underlying member method code with example usage: obj.add_arguments(cls, parser) and returns: parser