code: def project_masks_on_boxes(gt_masks, boxes, matched_idxs, M):
      # type: (Tensor, Tensor, Tensor, int) -> Tensor
      """
      Given segmentation masks and the bounding boxes corresponding
      to the location of the masks in the image, this function
      crops and resizes the masks in the position defined by the
      boxes. This prepares the masks for them to be fed to the
      loss computation as the targets.
      """
      matched_idxs = matched_idxs.to(boxes)
      rois = torch.cat([matched_idxs[:, None], boxes], dim=1)
      gt_masks = gt_masks[:, None].to(rois)
      return roi_align(gt_masks, rois, (M, M), 1.0)[:, 0]
  
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 3 for calling a global function with example usage: project_masks_on_boxes(gt_masks, boxes, matched_idxs, M) and returns: roi_align