code: def generate_rpn_on_range(
      weights_file,
      dataset_name,
      _proposal_file_ignored,
      output_dir,
      ind_range=None,
      gpu_id=0,
  ):
      """Run inference on all images in a dataset or over an index range of images
      in a dataset using a single GPU.
      """
      assert cfg.MODEL.RPN_ONLY or cfg.MODEL.FASTER_RCNN
  
      roidb, start_ind, end_ind, total_num_images = get_roidb(
          dataset_name, ind_range
      )
      logger.info(
          "Output will be saved to: {:s}".format(
              os.path.abspath(output_dir)
          )
      )
  
      model = model_builder.create(
          cfg.MODEL.TYPE, train=False, gpu_id=gpu_id
      )
      nu.initialize_gpu_from_weights_file(
          model,
          weights_file,
          gpu_id=gpu_id,
      )
      model_builder.add_inference_inputs(model)
      workspace.CreateNet(model.net)
  
      boxes, scores, ids = generate_proposals_on_roidb(
          model,
          roidb,
          start_ind=start_ind,
          end_ind=end_ind,
          total_num_images=total_num_images,
          gpu_id=gpu_id,
      )
  
      cfg_yaml = yaml.dump(cfg)
      if ind_range is not None:
          rpn_name = "rpn_proposals_range_%s_%s.pkl" % tuple(ind_range)
      else:
          rpn_name = "rpn_proposals.pkl"
      rpn_file = os.path.join(output_dir, rpn_name)
      save_object(
          dict(boxes=boxes, scores=scores, ids=ids, cfg=cfg_yaml),
          rpn_file,
      )
      logger.info(
          "Wrote RPN proposals to {}".format(os.path.abspath(rpn_file))
      )
      return boxes, scores, ids, rpn_file
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import cv2
  import datetime
  import logging
  import numpy
  import os
  import yaml
  from caffe2.python import core
  from caffe2.python import workspace
  from detectron.core.config import cfg
  from detectron.datasets import task_evaluation
  from detectron.datasets.json_dataset import JsonDataset
  from detectron.modeling import model_builder
  from detectron.utils.io import save_object
  from detectron.utils.timer import Timer
  import detectron.utils.blob
  import detectron.utils.c2
  import detectron.utils.env
  import detectron.utils.net
  import detectron.utils.subprocess
label_desc: Use image node_id 3 for calling a global function with example usage: generate_rpn_on_range(weights_file, dataset_name, _proposal_file_ignored, output_dir, ind_range, gpu_id) and returns: boxes,  scores,  ids,  rpn_file