code: def compute_proposals(img, num_proposals, cfg):
      img_w = len(img[0])
      img_h = len(img)
  
      if cfg is None:
          cfg = {}
      roi_ss_kvals = (
          (10, 500, 5)
          if "roi_ss_kvals" not in cfg
          else tuple(cfg["roi_ss_kvals"])
      )
      roi_ss_mm_iterations = (
          30
          if "roi_ss_mm_iterations" not in cfg
          else cfg["roi_ss_mm_iterations"]
      )
      roi_ss_min_size = (
          9 if "roi_ss_min_size" not in cfg else cfg["roi_ss_min_size"]
      )
      roi_ss_img_size = (
          200
          if "roi_ss_img_size" not in cfg
          else cfg["roi_ss_img_size"]
      )
      roi_min_side_rel = (
          0.04
          if "roi_min_side_rel" not in cfg
          else cfg["roi_min_side_rel"]
      )
      roi_max_side_rel = (
          0.4
          if "roi_max_side_rel" not in cfg
          else cfg["roi_max_side_rel"]
      )
      roi_min_area_rel = (
          2 * roi_min_side_rel * roi_min_side_rel
          if "roi_min_area_rel" not in cfg
          else cfg["roi_min_area_rel"]
      )
      roi_max_area_rel = (
          0.33 * roi_max_side_rel * roi_max_side_rel
          if "roi_max_area_rel" not in cfg
          else cfg["roi_max_area_rel"]
      )
      roi_max_aspect_ratio = (
          4.0
          if "roi_max_aspect_ratio" not in cfg
          else cfg["roi_max_aspect_ratio"]
      )
      roi_grid_aspect_ratios = (
          [1.0, 2.0, 0.5]
          if "roi_grid_aspect_ratios" not in cfg
          else cfg["roi_grid_aspect_ratios"]
      )
      debug_output = (
          False
          if not ("CNTK" in cfg and "DEBUG_OUTPUT" in cfg.CNTK)
          else cfg.CNTK.DEBUG_OUTPUT
      )
  
      scale = 1.0 * roi_ss_img_size / max(img.shape[:2])
      img = cv2.resize(
          img,
          (0, 0),
          fx=scale,
          fy=scale,
          interpolation=cv2.INTER_LINEAR,
      )
  
      roi_min_side = roi_min_side_rel * roi_ss_img_size
      roi_max_side = roi_max_side_rel * roi_ss_img_size
      roi_min_area = (
          roi_min_area_rel * roi_ss_img_size * roi_ss_img_size
      )
      roi_max_area = (
          roi_max_area_rel * roi_ss_img_size * roi_ss_img_size
      )
  
      if not ss_lib_loaded:
          load_selective_search_lib()
      rects = []
      tmp = []
      find_candidate_object_locations(
          img,
          tmp,
          kvals=roi_ss_kvals,
          min_size=roi_ss_min_size,
          max_merging_iterations=roi_ss_mm_iterations,
      )
      for k, d in enumerate(tmp):
          rects.append([d.left(), d.top(), d.right(), d.bottom()])
      filtered_rects = filterRois(
          rects,
          img_w,
          img_h,
          roi_min_area,
          roi_max_area,
          roi_min_side,
          roi_max_side,
          roi_max_aspect_ratio,
      )
      scaled_rects = np.array(filtered_rects) * (1 / scale)
      if debug_output:
          print(
              "selective search rois before | after filtering: {} | {}. Requested: {}".format(
                  len(rects), len(filtered_rects), num_proposals
              )
          )
  
      num_rects = scaled_rects.shape[0]
      np.random.seed(random_seed)
      if num_rects < num_proposals:
          try:
              shuffle = not cfg.CNTK.FORCE_DETERMINISTIC
          except:
              shuffle = True
  
          roi_min_side = roi_min_side_rel * min(img_w, img_h)
          roi_max_side = roi_max_side_rel * max(img_w, img_h)
          grid_proposals = compute_grid_proposals(
              num_proposals - num_rects,
              img_w,
              img_h,
              roi_min_side,
              roi_max_side,
              roi_grid_aspect_ratios,
              shuffle,
          )
          scaled_rects = np.vstack([scaled_rects, grid_proposals])
      elif num_rects > num_proposals:
          keep_inds = range(num_rects)
          keep_inds = np.random.choice(
              keep_inds, size=num_proposals, replace=False
          )
          scaled_rects = scaled_rects[keep_inds]
  
      return scaled_rects
  
imports: import os, sys
  import numpy
  import cv2
  from utils.rpn.bbox_transform import bbox_transform
  from utils.cython_modules.cython_bbox import bbox_overlaps
label_desc: Use image node_id 4 for calling a global function with example usage: compute_proposals(img, num_proposals, cfg) and returns: scaled_rects