class_docstr: Implement the basic Mask R-CNN losses and inference logic described in :paper:`Mask R-CNN`
class_docstr_tok: ["Implement","the","basic","Mask","R-CNN","losses","and","inference","logic","described","in",":","paper",":","`","Mask","R-CNN","`"]
docstr: Args:
      x: input region feature(s) provided by :class:`ROIHeads`.
      instances (list[Instances]): contains the boxes & labels corresponding
          to the input features.
          Exact format is up to its caller to decide.
          Typically, this is the foreground instances in training, with
          "proposal_boxes" field and other gt annotations.
          In inference, it contains boxes that are already predicted.
  
  Returns:
      A dict of losses in training. The predicted "instances" in inference.
docstr_tok: ["Args",":","x",":","input","region","feature","(","s",")","provided","by",":","class",":","`","ROIHeads","`",".","instances","(","list","[","Instances","]",")",":","contains","the","boxes","&","labels","corresponding","to","the","input","features",".","Exact","format","is","up","to","its","caller","to","decide",".","Typically",",","this","is","the","foreground","instances","in","training",",","with","``","proposal_boxes","''","field","and","other","gt","annotations",".","In","inference",",","it","contains","boxes","that","are","already","predicted",".","Returns",":","A","dict","of","losses","in","training",".","The","predicted","``","instances","''","in","inference","."]
code: def forward(self, x, instances: List[Instances]):
      """
      Args:
          x: input region feature(s) provided by :class:`ROIHeads`.
          instances (list[Instances]): contains the boxes & labels corresponding
              to the input features.
              Exact format is up to its caller to decide.
              Typically, this is the foreground instances in training, with
              "proposal_boxes" field and other gt annotations.
              In inference, it contains boxes that are already predicted.
  
      Returns:
          A dict of losses in training. The predicted "instances" in inference.
      """
      x = self.layers(x)
      if self.training:
          return {
              "loss_mask": mask_rcnn_loss(x, instances, self.vis_period)
              * self.loss_weight
          }
      else:
          mask_rcnn_inference(x, instances)
          return instances
  
imports: from typing import List
  import fvcore.nn.weight_init
  import torch
  from torch import nn
  from torch.nn import functional
  from detectron2.config import configurable
  from detectron2.layers import Conv2d, ConvTranspose2d, ShapeSpec, cat, get_norm
  from detectron2.layers.wrappers import move_device_like
  from detectron2.structures import Instances
  from detectron2.utils.events import get_event_storage
  from detectron2.utils.registry import Registry
label_desc: Use image node_id 3 for calling the BaseMaskRCNNHead obj's underlying member method code with example usage: obj.forward(x, instances) and returns: dict, instances