code: def maskrcnn_inference(x, labels):
      # type: (Tensor, List[Tensor]) -> List[Tensor]
      """
      From the results of the CNN, post process the masks
      by taking the mask corresponding to the class with max
      probability (which are of fixed size and directly output
      by the CNN) and return the masks in the mask field of the BoxList.
  
      Args:
          x (Tensor): the mask logits
          labels (list[BoxList]): bounding boxes that are used as
              reference, one for ech image
  
      Returns:
          results (list[BoxList]): one BoxList for each image, containing
              the extra field mask
      """
      mask_prob = x.sigmoid()
  
      # select masks corresponding to the predicted classes
      num_masks = x.shape[0]
      boxes_per_image = [label.shape[0] for label in labels]
      labels = torch.cat(labels)
      index = torch.arange(num_masks, device=labels.device)
      mask_prob = mask_prob[index, labels][:, None]
      mask_prob = mask_prob.split(boxes_per_image, dim=0)
  
      return mask_prob
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  import torchvision
  from torch import nn, Tensor
  from torchvision.ops import boxes, roi_align
  from .None import _utils
label_desc: Use image node_id 2 for calling a global function with example usage: maskrcnn_inference(x, labels) and returns: mask_prob