code: def _paste_mask(box, mask, shape):
      """
      Args:
          box: 4 float
          mask: MxM floats
          shape: h,w
      Returns:
          A uint8 binary image of hxw.
      """
      assert mask.shape[0] == mask.shape[1], mask.shape
  
      if cfg.MRCNN.ACCURATE_PASTE:
          # This method is accurate but much slower.
          mask = np.pad(mask, [(1, 1), (1, 1)], mode="constant")
          box = _scale_box(
              box, float(mask.shape[0]) / (mask.shape[0] - 2)
          )
  
          mask_pixels = np.arange(0.0, mask.shape[0]) + 0.5
          mask_continuous = interpolate.interp2d(
              mask_pixels, mask_pixels, mask, fill_value=0.0
          )
          h, w = shape
          ys = np.arange(0.0, h) + 0.5
          xs = np.arange(0.0, w) + 0.5
          ys = (ys - box[1]) / (box[3] - box[1]) * mask.shape[0]
          xs = (xs - box[0]) / (box[2] - box[0]) * mask.shape[1]
          # Waste a lot of compute since most indices are out-of-border
          res = mask_continuous(xs, ys)
          return (res >= 0.5).astype("uint8")
      else:
          # This method (inspired by Detectron) is less accurate but fast.
  
          # int() is floor
          # box fpcoor=0.0 -> intcoor=0.0
          x0, y0 = list(map(int, box[:2] + 0.5))
          # box fpcoor=h -> intcoor=h-1, inclusive
          x1, y1 = list(map(int, box[2:] - 0.5))  # inclusive
          x1 = max(x0, x1)  # require at least 1x1
          y1 = max(y0, y1)
  
          w = x1 + 1 - x0
          h = y1 + 1 - y0
  
          # rounding errors could happen here, because masks were not originally computed for this shape.
          # but it's hard to do better, because the network does not know the "original" scale
          mask = (cv2.resize(mask, (w, h)) > 0.5).astype("uint8")
          ret = np.zeros(shape, dtype="uint8")
          ret[y0 : y1 + 1, x0 : x1 + 1] = mask
          return ret
  
imports: import itertools
  import json
  import numpy
  import os
  import sys
  from collections import namedtuple
  from concurrent.futures import ThreadPoolExecutor
  from contextlib import ExitStack
  import cv2
  import pycocotools.mask
  import tqdm
  from scipy import interpolate
  from tensorpack.callbacks import Callback
  from tensorpack.tfutils.common import get_tf_version_tuple
  from tensorpack.utils import logger, get_tqdm
  from common import CustomResize, clip_boxes
  from config import config
  from data import get_eval_dataflow
  from dataset import DatasetRegistry
  from tensorpack.compat import tfv1
label_desc: Use image node_id 2 for calling a global function with example usage: _paste_mask(box, mask, shape) and returns: unknown, ret