class_docstr: YOLACT mask head used in https://arxiv.org/abs/1904.02689.
  
  This head outputs the mask prototypes for YOLACT.
  
  Args:
      in_channels (int): Number of channels in the input feature map.
      proto_channels (tuple[int]): Output channels of protonet convs.
      proto_kernel_sizes (tuple[int]): Kernel sizes of protonet convs.
      include_last_relu (Bool): If keep the last relu of protonet.
      num_protos (int): Number of prototypes.
      num_classes (int): Number of categories excluding the background
          category.
      loss_mask_weight (float): Reweight the mask loss by this factor.
      max_masks_to_train (int): Maximum number of masks to train for
          each image.
docstr: Forward feature from the upstream network to get prototypes and
  linearly combine the prototypes, using masks coefficients, into
  instance masks. Finally, crop the instance masks with given bboxes.
  
  Args:
      x (Tensor): Feature from the upstream network, which is
          a 4D-tensor.
      coeff_pred (list[Tensor]): Mask coefficients for each scale
          level with shape (N, num_anchors * num_protos, H, W).
      bboxes (list[Tensor]): Box used for cropping with shape
          (N, num_anchors * 4, H, W). During training, they are
          ground truth boxes. During testing, they are predicted
          boxes.
      img_meta (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      sampling_results (List[:obj:``SamplingResult``]): Sampler results
          for each image.
  
  Returns:
      list[Tensor]: Predicted instance segmentation masks.
docstr_tok: ["Forward","feature","from","the","upstream","network","to","get","prototypes","and","linearly","combine","the","prototypes",",","using","masks","coefficients",",","into","instance","masks",".","Finally",",","crop","the","instance","masks","with","given","bboxes",".","Args",":","x","(","Tensor",")",":","Feature","from","the","upstream","network",",","which","is","a","4D-tensor",".","coeff_pred","(","list","[","Tensor","]",")",":","Mask","coefficients","for","each","scale","level","with","shape","(","N",",","num_anchors","*","num_protos",",","H",",","W",")",".","bboxes","(","list","[","Tensor","]",")",":","Box","used","for","cropping","with","shape","(","N",",","num_anchors","*","4",",","H",",","W",")",".","During","training",",","they","are","ground","truth","boxes",".","During","testing",",","they","are","predicted","boxes",".","img_meta","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","sampling_results","(","List","[",":","obj",":","``","SamplingResult","``","]",")",":","Sampler","results","for","each","image",".","Returns",":","list","[","Tensor","]",":","Predicted","instance","segmentation","masks","."]
code: def forward(
      self, x, coeff_pred, bboxes, img_meta, sampling_results=None
  ):
      """Forward feature from the upstream network to get prototypes and
      linearly combine the prototypes, using masks coefficients, into
      instance masks. Finally, crop the instance masks with given bboxes.
  
      Args:
          x (Tensor): Feature from the upstream network, which is
              a 4D-tensor.
          coeff_pred (list[Tensor]): Mask coefficients for each scale
              level with shape (N, num_anchors * num_protos, H, W).
          bboxes (list[Tensor]): Box used for cropping with shape
              (N, num_anchors * 4, H, W). During training, they are
              ground truth boxes. During testing, they are predicted
              boxes.
          img_meta (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          sampling_results (List[:obj:``SamplingResult``]): Sampler results
              for each image.
  
      Returns:
          list[Tensor]: Predicted instance segmentation masks.
      """
      prototypes = self.protonet(x)
      prototypes = prototypes.permute(0, 2, 3, 1).contiguous()
  
      num_imgs = x.size(0)
      # Training state
      if self.training:
          coeff_pred_list = []
          for coeff_pred_per_level in coeff_pred:
              coeff_pred_per_level = coeff_pred_per_level.permute(
                  0, 2, 3, 1
              ).reshape(num_imgs, -1, self.num_protos)
              coeff_pred_list.append(coeff_pred_per_level)
          coeff_pred = torch.cat(coeff_pred_list, dim=1)
  
      mask_pred_list = []
      for idx in range(num_imgs):
          cur_prototypes = prototypes[idx]
          cur_coeff_pred = coeff_pred[idx]
          cur_bboxes = bboxes[idx]
          cur_img_meta = img_meta[idx]
  
          # Testing state
          if not self.training:
              bboxes_for_cropping = cur_bboxes
          else:
              cur_sampling_results = sampling_results[idx]
              pos_assigned_gt_inds = (
                  cur_sampling_results.pos_assigned_gt_inds
              )
              bboxes_for_cropping = cur_bboxes[
                  pos_assigned_gt_inds
              ].clone()
              pos_inds = cur_sampling_results.pos_inds
              cur_coeff_pred = cur_coeff_pred[pos_inds]
  
          # Linearly combine the prototypes with the mask coefficients
          mask_pred = cur_prototypes @ cur_coeff_pred.t()
          mask_pred = torch.sigmoid(mask_pred)
  
          h, w = cur_img_meta["img_shape"][:2]
          bboxes_for_cropping[:, 0] /= w
          bboxes_for_cropping[:, 1] /= h
          bboxes_for_cropping[:, 2] /= w
          bboxes_for_cropping[:, 3] /= h
  
          mask_pred = self.crop(mask_pred, bboxes_for_cropping)
          mask_pred = mask_pred.permute(2, 0, 1).contiguous()
          mask_pred_list.append(mask_pred)
      return mask_pred_list
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, xavier_init
  from mmcv.runner import force_fp32
  from mmdet.core import build_sampler, fast_nms, images_to_levels, multi_apply
  from ..builder import HEADS, build_loss
  from .anchor_head import AnchorHead
label_desc: Use image node_id 4 for calling the YOLACTProtonet obj's underlying member method code with example usage: obj.forward(x, coeff_pred, bboxes, img_meta, sampling_results) and returns: mask_pred_list