class_docstr: TensorMask model. Creates FPN backbone, anchors and a head for classification
  and box regression. Calculates and applies proper losses to class, box, and
  masks.
docstr: Args:
      batched_inputs: a list, batched outputs of :class:`DetectionTransform` .
          Each item in the list contains the inputs for one image.
      For now, each item in the list is a dict that contains:
          image: Tensor, image in (C, H, W) format.
          instances: Instances
          Other information that's included in the original dicts, such as:
              "height", "width" (int): the output resolution of the model, used in inference.
                  See :meth:`postprocess` for details.
   Returns:
      losses (dict[str: Tensor]): mapping from a named loss to a tensor
          storing the loss. Used during training only.
docstr_tok: ["Args",":","batched_inputs",":","a","list",",","batched","outputs","of",":","class",":","`","DetectionTransform","`",".","Each","item","in","the","list","contains","the","inputs","for","one","image",".","For","now",",","each","item","in","the","list","is","a","dict","that","contains",":","image",":","Tensor",",","image","in","(","C",",","H",",","W",")","format",".","instances",":","Instances","Other","information","that","'s","included","in","the","original","dicts",",","such","as",":","``","height","''",",","``","width","''","(","int",")",":","the","output","resolution","of","the","model",",","used","in","inference",".","See",":","meth",":","`","postprocess","`","for","details",".","Returns",":","losses","(","dict","[","str",":","Tensor","]",")",":","mapping","from","a","named","loss","to","a","tensor","storing","the","loss",".","Used","during","training","only","."]
code: def forward(self, batched_inputs):
      """
      Args:
          batched_inputs: a list, batched outputs of :class:`DetectionTransform` .
              Each item in the list contains the inputs for one image.
          For now, each item in the list is a dict that contains:
              image: Tensor, image in (C, H, W) format.
              instances: Instances
              Other information that's included in the original dicts, such as:
                  "height", "width" (int): the output resolution of the model, used in inference.
                      See :meth:`postprocess` for details.
       Returns:
          losses (dict[str: Tensor]): mapping from a named loss to a tensor
              storing the loss. Used during training only.
      """
      images = self.preprocess_image(batched_inputs)
      if "instances" in batched_inputs[0]:
          gt_instances = [
              x["instances"].to(self.device) for x in batched_inputs
          ]
      else:
          gt_instances = None
  
      features = self.backbone(images.tensor)
      features = [features[f] for f in self.in_features]
      # apply the TensorMask head
      pred_logits, pred_deltas, pred_masks = self.head(features)
      # generate anchors based on features, is it image specific?
      anchors, unit_lengths, indexes = self.anchor_generator(features)
  
      if self.training:
          # get ground truths for class labels and box targets, it will label each anchor
          (
              gt_class_info,
              gt_delta_info,
              gt_mask_info,
              num_fg,
          ) = self.get_ground_truth(
              anchors, unit_lengths, indexes, gt_instances
          )
          # compute the loss
          return self.losses(
              gt_class_info,
              gt_delta_info,
              gt_mask_info,
              num_fg,
              pred_logits,
              pred_deltas,
              pred_masks,
          )
      else:
          # do inference to get the output
          results = self.inference(
              pred_logits,
              pred_deltas,
              pred_masks,
              anchors,
              indexes,
              images,
          )
          processed_results = []
          for results_im, input_im, image_size in zip(
              results, batched_inputs, images.image_sizes
          ):
              height = input_im.get("height", image_size[0])
              width = input_im.get("width", image_size[1])
              # this is to do post-processing with the image size
              result_box, result_mask = results_im
              r = _postprocess(result_box, result_mask, height, width)
              processed_results.append({"instances": r})
          return processed_results
  
imports: import copy
  import math
  from typing import List
  import torch
  import torch.nn.functional
  from fvcore.nn import sigmoid_focal_loss_star_jit, smooth_l1_loss
  from torch import nn
  from detectron2.layers import ShapeSpec, batched_nms, cat, paste_masks_in_image
  from detectron2.modeling.anchor_generator import DefaultAnchorGenerator
  from detectron2.modeling.backbone import build_backbone
  from detectron2.modeling.box_regression import Box2BoxTransform
  from detectron2.modeling.meta_arch.build import META_ARCH_REGISTRY
  from detectron2.modeling.meta_arch.retinanet import permute_to_N_HWA_K
  from detectron2.structures import Boxes, ImageList, Instances
  from tensormask.layers import SwapAlign2Nat
label_desc: Use image node_id 3 for calling the TensorMask obj's underlying member method code with example usage: obj.forward(batched_inputs) and returns: self, processed_results