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",")"]
code: def forward(
      self, x: Dict, *args, **kwargs
  ) -> Union[Tuple[Tensor, ...], Tuple[Any, ...], Dict]:
      if isinstance(x, Dict):
          input_tensor = x["image"]
          input_labels = x["label"]
      else:
          raise NotImplementedError(
              "Input to MaskRCNN should be a Dict of List of Tensors"
          )
  
      assert isinstance(input_tensor, List)
      assert isinstance(input_labels, List)
  
      in_channels, in_height, in_width = input_tensor[0].shape
  
      self.reset_generalized_rcnn_transform(
          height=in_height, width=in_width
      )
  
      # The mask rcnn model expects labels, since it computes the loss.
      outputs = self.model(input_tensor, targets=input_labels)
  
      if not self.training:
          detections = []
          for i, elem in enumerate(outputs):
              # We must normalize by image size, since this is what the downstream
              # evaluator expects.
              elem["boxes"][:, 0::2] /= input_tensor[i].shape[2]
              elem["boxes"][:, 1::2] /= input_tensor[i].shape[1]
  
              # predicted masks are in [N, 1, H, W] format
              # for evaluation, we need them in [N, H, W] format
              masks = elem["masks"]
              # [N, 1, H, W] --> [N, H, W]
              masks = masks.squeeze(1)
  
              elem_detections = DetectionPredTuple(
                  labels=elem["labels"],
                  scores=elem["scores"],
                  boxes=elem["boxes"],
                  masks=masks,
              )
              detections.append(elem_detections)
          return {"detections": detections}
  
      if hasattr(self.model.backbone, "get_augmented_tensor"):
          outputs[
              "augmented_tensor"
          ] = self.model.backbone.get_augmented_tensor()
  
      return outputs
  
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 8 for calling the MaskRCNNDetector obj's underlying member method code with example usage: obj.forward(x) and returns: outputs, dict