code: def generate_proposals(
      predictor, test_data, imdb, vis=False, thresh=0.0
  ):
      """
      Generate detections results using RPN.
      :param predictor: Predictor
      :param test_data: data iterator, must be non-shuffled
      :param imdb: image database
      :param vis: controls visualization
      :param thresh: thresh for valid detections
      :return: list of detected boxes
      """
      assert vis or not test_data.shuffle
      data_names = [k[0] for k in test_data.provide_data]
  
      i = 0
      t = time.time()
      imdb_boxes = list()
      original_boxes = list()
      for im_info, data_batch in test_data:
          t1 = time.time() - t
          t = time.time()
  
          scale = im_info[0, 2]
          scores, boxes, data_dict = im_proposal(
              predictor, data_batch, data_names, scale
          )
          print(scores.shape, boxes.shape, file=sys.stderr)
          t2 = time.time() - t
          t = time.time()
  
          # assemble proposals
          dets = np.hstack((boxes, scores))
          original_boxes.append(dets)
  
          # filter proposals
          keep = np.where(dets[:, 4:] > thresh)[0]
          dets = dets[keep, :]
          imdb_boxes.append(dets)
  
          if vis:
              vis_all_detection(
                  data_dict["data"].asnumpy(), [dets], ["obj"], scale
              )
  
          logger.info(
              "generating %d/%d " % (i + 1, imdb.num_images)
              + "proposal %d " % (dets.shape[0])
              + "data %.4fs net %.4fs" % (t1, t2)
          )
          i += 1
  
      assert (
          len(imdb_boxes) == imdb.num_images
      ), "calculations not complete"
  
      # save results
      rpn_folder = os.path.join(imdb.root_path, "rpn_data")
      if not os.path.exists(rpn_folder):
          os.mkdir(rpn_folder)
  
      rpn_file = os.path.join(rpn_folder, imdb.name + "_rpn.pkl")
      with open(rpn_file, "wb") as f:
          pickle.dump(imdb_boxes, f, pickle.HIGHEST_PROTOCOL)
  
      if thresh > 0:
          full_rpn_file = os.path.join(
              rpn_folder, imdb.name + "_full_rpn.pkl"
          )
          with open(full_rpn_file, "wb") as f:
              pickle.dump(original_boxes, f, pickle.HIGHEST_PROTOCOL)
  
      logger.info("wrote rpn proposals to %s" % rpn_file)
      return imdb_boxes
  
imports: from __future__ import print_function
  import os
  import sys
  import time
  import mxnet
  import numpy
  from builtins import range
  from mxnet.module import Module
  from .module import MutableModule
  from rcnn.logger import logger
  from rcnn.config import config
  from rcnn.io import image
  from rcnn.processing.bbox_transform import bbox_pred, clip_boxes
  from rcnn.processing.nms import py_nms_wrapper, cpu_nms_wrapper, gpu_nms_wrapper
  from rcnn.processing.bbox_transform import bbox_overlaps
label_desc: Use image node_id 4 for calling a global function with example usage: generate_proposals(predictor, test_data, imdb, vis, thresh) and returns: imdb_boxes