text: """Evaluate a network with Detectron."""
  from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  
  import argparse
  import cv2  # NOQA (Must import before importing caffe2 due to bug in cv2)
  import os
  import pprint
  import sys
  import time
  
  from caffe2.python import workspace
  
  from detectron.core.config import assert_and_infer_cfg
  from detectron.core.config import cfg
  from detectron.core.config import merge_cfg_from_file
  from detectron.core.config import merge_cfg_from_list
  from detectron.core.test_engine import run_inference
  from detectron.utils.logging import setup_logging
  import detectron.utils.c2 as c2_utils
  
  c2_utils.import_detectron_ops()
  
  # OpenCL may be enabled by default in OpenCV3; disable it because it's not
  # thread safe and causes unwanted GPU memory allocations.
  cv2.ocl.setUseOpenCL(False)
  
  def parse_args():
      parser = argparse.ArgumentParser(description='Test a Fast R-CNN network')
      parser.add_argument(
          '--cfg',
          dest='cfg_file',
          help='optional config file',
          default=None,
          type=str
      )
      parser.add_argument(
          '--wait',
          dest='wait',
          help='wait until net file exists',
          default=True,
          type=bool
      )
      parser.add_argument(
          '--vis', dest='vis', help='visualize detections', action='store_true'
      )
      parser.add_argument(
          '--multi-gpu-testing',
          dest='multi_gpu_testing',
          help='using cfg.NUM_GPUS for inference',
          action='store_true'
      )
      parser.add_argument(
          '--range',
          dest='range',
          help='start (inclusive) and end (exclusive) indices',
          default=None,
          type=int,
          nargs=2
      )
      parser.add_argument(
          'opts',
          help='See detectron/core/config.py for all options',
          default=None,
          nargs=argparse.REMAINDER
      )
      if len(sys.argv) == 1:
          parser.print_help()
          sys.exit(1)
      return parser.parse_args()
  
  
  if __name__ == '__main__':
      workspace.GlobalInit(['caffe2', '--caffe2_log_level=0'])
      logger = setup_logging(__name__)
      args = parse_args()
      logger.info('Called with args:')
      logger.info(args)
      if args.cfg_file is not None:
          merge_cfg_from_file(args.cfg_file)
      if args.opts is not None:
          merge_cfg_from_list(args.opts)
      assert_and_infer_cfg()
      logger.info('Testing with config:')
      logger.info(pprint.pformat(cfg))
  
      # output_dir = get_output_dir(cfg.TRAIN.DATASETS, training=True)
      output_dir = '/mnt/fcav/self_training/object_detection/upperbound1/train/voc_GTA_caronly_train:cityscapes_caronly_train:voc_GTA_caronly_val/generalized_rcnn'
      files = os.listdir(output_dir)
      for f in files:
          iter_string = re.findall(r'(?<=model_iter)\d+(?=\.pkl)', f)
          if len(iter_string) > 0:
              checkpoint_iter = int(iter_string[0])
              start_iter = checkpoint_iter + 1
              resume_weights_file = f
          # Override the initialization weights with the found checkpoint
          weights_file = os.path.join(output_dir, resume_weights_file)
          logger.info(
              '========> Resuming from checkpoint {} at start iter {}'.
                  format(weights_file, start_iter)
          )
  
      run_inference(
          weights_file,
          ind_range=args.range,
          multi_gpu_testing=args.multi_gpu_testing,
          check_expected_results=True,
      )
  
  