code: def paste_mask_in_image(mask, box, im_h, im_w):
      # type: (Tensor, Tensor, int, int) -> Tensor
  
      # refer to: https://github.com/pytorch/vision/issues/5845
      TO_REMOVE = 1
      w = int(box[2] - box[0] + TO_REMOVE)
      h = int(box[3] - box[1] + TO_REMOVE)
      w = max(w, 1)
      h = max(h, 1)
  
      # Set shape to [batch, C, H, W]
      # 因为后续的bilinear操作只支持4-D的Tensor
      mask = mask.expand(
          (1, 1, -1, -1)
      )  # -1 means not changing the size of that dimension
  
      # Resize mask
      mask = F.interpolate(
          mask, size=(h, w), mode="bilinear", align_corners=False
      )
      mask = mask[0][0]  # [batch, C, H, W] -> [H, W]
  
      im_mask = torch.zeros(
          (im_h, im_w), dtype=mask.dtype, device=mask.device
      )
      # 填入原图的目标区域(防止越界)
      x_0 = max(box[0], 0)
      x_1 = min(box[2] + 1, im_w)
      y_0 = max(box[1], 0)
      y_1 = min(box[3] + 1, im_h)
  
      # 将resize后的mask填入对应目标区域
      im_mask[y_0:y_1, x_0:x_1] = mask[
          (y_0 - box[1]) : (y_1 - box[1]),
          (x_0 - box[0]) : (x_1 - box[0]),
      ]
      return im_mask
  
imports: import math
  from typing import List, Tuple, Dict, Optional
  import torch
  from torch import nn, Tensor
  import torch.nn.functional
  import torchvision
  from .image_list import ImageList
label_desc: Use image node_id 10 for calling a global function with example usage: paste_mask_in_image(mask, box, im_h, im_w) and returns: im_mask