docstr: Arguments:
      features (list[Tensor]): FPN feature map tensors in high to low resolution.
          Each tensor in the list correspond to different feature levels.
  
  Returns:
      pred_logits (list[Tensor]): #lvl tensors, each has shape (N, AxK, Hi, Wi).
          The tensor predicts the classification probability
          at each spatial position for each of the A anchors and K object
          classes.
      pred_deltas (list[Tensor]): #lvl tensors, each has shape (N, Ax4, Hi, Wi).
          The tensor predicts 4-vector (dx,dy,dw,dh) box
          regression values for every anchor. These values are the
          relative offset between the anchor and the ground truth box.
      pred_masks (list(list[Tensor])): #lvl list of tensors, each is a list of
          A tensors of shape (N, M_{i,a}, Hi, Wi).
          The tensor predicts a dense set of M_ixM_i masks at every location.
docstr_tok: ["Arguments",":","features","(","list","[","Tensor","]",")",":","FPN","feature","map","tensors","in","high","to","low","resolution",".","Each","tensor","in","the","list","correspond","to","different","feature","levels",".","Returns",":","pred_logits","(","list","[","Tensor","]",")",":","#","lvl","tensors",",","each","has","shape","(","N",",","AxK",",","Hi",",","Wi",")",".","The","tensor","predicts","the","classification","probability","at","each","spatial","position","for","each","of","the","A","anchors","and","K","object","classes",".","pred_deltas","(","list","[","Tensor","]",")",":","#","lvl","tensors",",","each","has","shape","(","N",",","Ax4",",","Hi",",","Wi",")",".","The","tensor","predicts","4-vector","(","dx",",","dy",",","dw",",","dh",")","box","regression","values","for","every","anchor",".","These","values","are","the","relative","offset","between","the","anchor","and","the","ground","truth","box",".","pred_masks","(","list","(","list","[","Tensor","]",")",")",":","#","lvl","list","of","tensors",",","each","is","a","list","of","A","tensors","of","shape","(","N",",","M_","{","i",",","a","}",",","Hi",",","Wi",")",".","The","tensor","predicts","a","dense","set","of","M_ixM_i","masks","at","every","location","."]
code: def forward(self, features):
      """
      Arguments:
          features (list[Tensor]): FPN feature map tensors in high to low resolution.
              Each tensor in the list correspond to different feature levels.
  
      Returns:
          pred_logits (list[Tensor]): #lvl tensors, each has shape (N, AxK, Hi, Wi).
              The tensor predicts the classification probability
              at each spatial position for each of the A anchors and K object
              classes.
          pred_deltas (list[Tensor]): #lvl tensors, each has shape (N, Ax4, Hi, Wi).
              The tensor predicts 4-vector (dx,dy,dw,dh) box
              regression values for every anchor. These values are the
              relative offset between the anchor and the ground truth box.
          pred_masks (list(list[Tensor])): #lvl list of tensors, each is a list of
              A tensors of shape (N, M_{i,a}, Hi, Wi).
              The tensor predicts a dense set of M_ixM_i masks at every location.
      """
      pred_logits = [
          self.cls_score(self.cls_subnet(x)) for x in features
      ]
      pred_deltas = [
          self.bbox_pred(self.bbox_subnet(x)) for x in features
      ]
  
      pred_masks = None
      if self.mask_on:
          mask_feats = [self.mask_subnet(x) for x in features]
  
          if self.bipyramid_on:
              mask_feat_high_res = mask_feats[0]
              H, W = mask_feat_high_res.shape[-2:]
              mask_feats_up = []
              for lvl, mask_feat in enumerate(mask_feats):
                  lambda_val = 2.0**lvl
                  mask_feat_up = mask_feat
                  if lvl > 0:
                      mask_feat_up = F.interpolate(
                          mask_feat,
                          scale_factor=lambda_val,
                          mode="bilinear",
                          align_corners=False,
                      )
                  mask_feats_up.append(
                      self.mask_fuse(
                          mask_feat_up[:, :, :H, :W]
                          + mask_feat_high_res
                      )
                  )
              mask_feats = mask_feats_up
  
          pred_masks = []
          for lvl, mask_feat in enumerate(mask_feats):
              cur_masks = []
              for mask_size in self.mask_sizes:
                  cur_mask_module = getattr(
                      self, "mask_pred_%02d" % mask_size
                  )
                  cur_mask = cur_mask_module(mask_feat)
                  if self.align_on:
                      if self.bipyramid_on:
                          cur_mask_module = getattr(
                              self, "align2nat_%02d" % lvl
                          )
                          cur_mask = cur_mask_module(cur_mask)
                      else:
                          cur_mask = self.align2nat(cur_mask)
                  cur_masks.append(cur_mask)
              pred_masks.append(cur_masks)
      return pred_logits, pred_deltas, pred_masks
  
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 2 for calling the TensorMaskHead obj's underlying member method code with example usage: obj.forward(features) and returns: pred_logits,  pred_deltas,  pred_masks