def run_inference(args, ind_range=None, multi_gpu_testing=False, gpu_id=0, check_expected_results=False): parent_func, child_func = get_eval_functions() is_parent = ind_range is None def result_getter(): if is_parent: # Parent case: # In this case we're either running inference on the entire dataset in a # single process or (if multi_gpu_testing is True) using this process to # launch subprocesses that each run inference on a range of the dataset all_results = {} datasets, roidbs, all_boxes_list = [], [], [] for i in range(len(cfg.TEST.DATASETS)): # for each dataset dataset_name, proposal_file = get_inference_dataset(i) output_dir = args.output_dir # results = parent_func( # call function 'test_net_on_dataset' dataset, roidb, all_boxes = parent_func( # call function 'test_net_on_dataset' args, dataset_name, proposal_file, output_dir, multi_gpu=multi_gpu_testing) datasets.append(dataset) roidbs.append(roidb) all_boxes_list.append(all_boxes) # all_results.update(results) # task_evaluation.evaluate_mAP_combine(datasets, roidbs, all_boxes_list, output_dir) task_evaluation.evaluate_mAP(datasets, roidbs, all_boxes_list, output_dir) # return all_results else: # Subprocess child case: # In this case test_net was called via subprocess.Popen to execute on a # range of inputs on a single dataset dataset_name, proposal_file = get_inference_dataset( 0, is_parent=False) output_dir = args.output_dir return child_func( # call function 'test_net' args, dataset_name, proposal_file, output_dir, ind_range=ind_range, gpu_id=gpu_id) all_results = result_getter() if check_expected_results and is_parent: task_evaluation.check_expected_results(all_results, atol=cfg.EXPECTED_RESULTS_ATOL, rtol=cfg.EXPECTED_RESULTS_RTOL) task_evaluation.log_copy_paste_friendly_results(all_results) return all_results
def main(ind_range=None, multi_gpu_testing=False): all_results = run_inference(ind_range=ind_range, multi_gpu_testing=multi_gpu_testing) if not ind_range: task_evaluation.check_expected_results(all_results, atol=cfg.EXPECTED_RESULTS_ATOL, rtol=cfg.EXPECTED_RESULTS_RTOL) task_evaluation.log_copy_paste_friendly_results(all_results)
def run_inference(args, ind_range=None, multi_gpu_testing=False, gpu_id=0, check_expected_results=False, tb_logger=None, cur_iter=-1): global tblogger global curiter tblogger = tb_logger curiter = cur_iter parent_func, child_func = get_eval_functions() is_parent = ind_range is None def result_getter(): if is_parent: # Parent case: # In this case we're either running inference on the entire dataset in a # single process or (if multi_gpu_testing is True) using this process to # launch subprocesses that each run inference on a range of the dataset all_results = {} for i in range(len(cfg.TEST.DATASETS)): dataset_name, proposal_file = get_inference_dataset( i, cfg.TEST.DATASETS[i]) output_dir = args.output_dir results = parent_func(args, dataset_name, proposal_file, output_dir, multi_gpu=multi_gpu_testing) all_results.update(results) return all_results else: # Subprocess child case: # In this case test_net was called via subprocess.Popen to execute on a # range of inputs on a single dataset dataset_name, proposal_file = \ get_inference_dataset(0, cfg.TEST.DATASETS[0], is_parent=False) output_dir = args.output_dir return child_func(args, dataset_name, proposal_file, output_dir, ind_range=ind_range, gpu_id=gpu_id) all_results = result_getter() if check_expected_results and is_parent: task_evaluation.check_expected_results(all_results, atol=cfg.EXPECTED_RESULTS_ATOL, rtol=cfg.EXPECTED_RESULTS_RTOL) task_evaluation.log_copy_paste_friendly_results(all_results) return all_results
def run_inference(args, ind_range=None, multi_gpu_testing=False, gpu_id=0, check_expected_results=False): parent_func, child_func = get_eval_functions() is_parent = ind_range is None def result_getter(): if is_parent: # Parent case: # In this case we're either running inference on the entire dataset in a # single process or (if multi_gpu_testing is True) using this process to # launch subprocesses that each run inference on a range of the dataset print('test_engine.py result_getter() parent start') print('multi gpu test: ', multi_gpu_testing) print('range(len(cfg.TEST.DATASETS): ', range(len(cfg.TEST.DATASETS))) print(cfg.TEST.DATASETS) all_results = {} for i in range(len(cfg.TEST.DATASETS)): dataset_name, proposal_file = get_inference_dataset(i) output_dir = args.output_dir results = parent_func(args, dataset_name, proposal_file, output_dir, multi_gpu=multi_gpu_testing) all_results.update(results) print('all results update check: ', len(all_results)) return all_results else: # Subprocess child case: # In this case test_net was called via subprocess.Popen to execute on a # range of inputs on a single dataset print('test_engine.py result_getter() child start') dataset_name, proposal_file = get_inference_dataset( 0, is_parent=False) output_dir = args.output_dir return child_func(args, dataset_name, proposal_file, output_dir, ind_range=ind_range, gpu_id=gpu_id) all_results = result_getter() if check_expected_results and is_parent: task_evaluation.check_expected_results(all_results, atol=cfg.EXPECTED_RESULTS_ATOL, rtol=cfg.EXPECTED_RESULTS_RTOL) task_evaluation.log_copy_paste_friendly_results(all_results) return all_results
def main(ind_range=None, multi_gpu_testing=False): all_results = run_inference( ind_range=ind_range, multi_gpu_testing=multi_gpu_testing ) if not ind_range: task_evaluation.check_expected_results( all_results, atol=cfg.EXPECTED_RESULTS_ATOL, rtol=cfg.EXPECTED_RESULTS_RTOL ) task_evaluation.log_copy_paste_friendly_results(all_results)
def run_inference( args, ind_range=None, multi_gpu_testing=False, gpu_id=0, check_expected_results=False): parent_func, child_func = get_eval_functions() is_parent = ind_range is None def result_getter(): if is_parent: # Parent case: # In this case we're either running inference on the entire dataset in a # single process or (if multi_gpu_testing is True) using this process to # launch subprocesses that each run inference on a range of the dataset all_results = {} for i in range(len(cfg.TEST.DATASETS)): dataset_name, proposal_file = get_inference_dataset(i) output_dir = args.output_dir results = parent_func( args, dataset_name, proposal_file, output_dir, multi_gpu=multi_gpu_testing ) all_results.update(results) return all_results else: # Subprocess child case: # In this case test_net was called via subprocess.Popen to execute on a # range of inputs on a single dataset dataset_name, proposal_file = get_inference_dataset(0, is_parent=False) output_dir = args.output_dir return child_func( args, dataset_name, proposal_file, output_dir, ind_range=ind_range, gpu_id=gpu_id ) all_results = result_getter() if check_expected_results and is_parent: task_evaluation.check_expected_results( all_results, atol=cfg.EXPECTED_RESULTS_ATOL, rtol=cfg.EXPECTED_RESULTS_RTOL ) task_evaluation.log_copy_paste_friendly_results(all_results) return all_results
def main(ind_range=None, multi_gpu_testing=False): output_dir = get_output_dir(training=False) all_results = run_inference(output_dir, ind_range=ind_range, multi_gpu_testing=multi_gpu_testing) if not ind_range: task_evaluation.check_expected_results(all_results, atol=cfg.EXPECTED_RESULTS_ATOL, rtol=cfg.EXPECTED_RESULTS_RTOL) import json json.dump(all_results, open(os.path.join(output_dir, 'bbox_results_all.json'), 'w')) task_evaluation.log_copy_paste_friendly_results(all_results)
def do_reval(dataset_name, output_dir, args): dataset = JsonDataset(dataset_name) with open(os.path.join(output_dir, 'detections.pkl'), 'rb') as f: dets = pickle.load(f) # Override config with the one saved in the detections file if args.cfg_file is not None: core.config.merge_cfg_from_cfg(yaml.safe_load(dets['cfg'])) else: core.config._merge_a_into_b(yaml.safe_load(dets['cfg']), cfg) results = task_evaluation.evaluate_all(dataset, dets['all_boxes'], dets['all_segms'], dets['all_keyps'], output_dir, use_matlab=args.matlab_eval) task_evaluation.log_copy_paste_friendly_results(results)
def main(ind_range=None, multi_gpu_testing=False): # Determine which parent or child function should handle inference if cfg.MODEL.RPN_ONLY: child_func = generate_rpn_on_range parent_func = generate_rpn_on_dataset elif cfg.RETINANET.RETINANET_ON: child_func = test_retinanet parent_func = test_retinanet_on_dataset else: # Generic case that handles all network types other than RPN-only nets # and RetinaNet child_func = test_net parent_func = test_net_on_dataset is_parent = ind_range is None if is_parent: # Parent case: # In this case we're either running inference on the entire dataset in a # single process or (if multi_gpu_testing is True) using this process to # launch subprocesses that each run inference on a range of the dataset if len(cfg.TEST.DATASETS) == 0: cfg.TEST.DATASETS = (cfg.TEST.DATASET, ) cfg.TEST.PROPOSAL_FILES = (cfg.TEST.PROPOSAL_FILE, ) all_results = {} for i in range(len(cfg.TEST.DATASETS)): cfg.TEST.DATASET = cfg.TEST.DATASETS[i] if cfg.TEST.PRECOMPUTED_PROPOSALS: cfg.TEST.PROPOSAL_FILE = cfg.TEST.PROPOSAL_FILES[i] results = parent_func(multi_gpu=multi_gpu_testing) all_results.update(results) task_evaluation.check_expected_results( all_results, atol=cfg.EXPECTED_RESULTS_ATOL, rtol=cfg.EXPECTED_RESULTS_RTOL ) task_evaluation.log_copy_paste_friendly_results(all_results) else: # Subprocess child case: # In this case test_net was called via subprocess.Popen to execute on a # range of inputs on a single dataset (i.e., use cfg.TEST.DATASET and # don't loop over cfg.TEST.DATASETS) child_func(ind_range=ind_range)
def do_reval(dataset_name, output_dir, args): dataset = JsonDataset(dataset_name) with open(os.path.join(output_dir, 'detections.pkl'), 'rb') as f: dets = pickle.load(f) # Override config with the one saved in the detections file if args.cfg_file is not None: core.config.merge_cfg_from_cfg(yaml.load(dets['cfg'])) else: core.config._merge_a_into_b(yaml.load(dets['cfg']), cfg) results = task_evaluation.evaluate_all( dataset, dets['all_boxes'], dets['all_segms'], dets['all_keyps'], output_dir, use_matlab=args.matlab_eval ) task_evaluation.log_copy_paste_friendly_results(results)
def main(ind_range=None, multi_gpu_testing=False): # Determine which parent or child function should handle inference if cfg.MODEL.RPN_ONLY: child_func = generate_rpn_on_range parent_func = generate_rpn_on_dataset elif cfg.RETINANET.RETINANET_ON: child_func = test_retinanet parent_func = test_retinanet_on_dataset else: # Generic case that handles all network types other than RPN-only nets # and RetinaNet child_func = test_net parent_func = test_net_on_dataset is_parent = ind_range is None if is_parent: # Parent case: # In this case we're either running inference on the entire dataset in a # single process or (if multi_gpu_testing is True) using this process to # launch subprocesses that each run inference on a range of the dataset if len(cfg.TEST.DATASETS) == 0: cfg.TEST.DATASETS = (cfg.TEST.DATASET, ) cfg.TEST.PROPOSAL_FILES = (cfg.TEST.PROPOSAL_FILE, ) all_results = {} for i in range(len(cfg.TEST.DATASETS)): cfg.TEST.DATASET = cfg.TEST.DATASETS[i] if cfg.TEST.PRECOMPUTED_PROPOSALS: cfg.TEST.PROPOSAL_FILE = cfg.TEST.PROPOSAL_FILES[i] results = parent_func(multi_gpu=multi_gpu_testing) all_results.update(results) task_evaluation.check_expected_results(all_results, atol=cfg.EXPECTED_RESULTS_ATOL, rtol=cfg.EXPECTED_RESULTS_RTOL) task_evaluation.log_copy_paste_friendly_results(all_results) else: # Subprocess child case: # In this case test_net was called via subprocess.Popen to execute on a # range of inputs on a single dataset (i.e., use cfg.TEST.DATASET and # don't loop over cfg.TEST.DATASETS) child_func(ind_range=ind_range)
def run_inference(args, ind_range=None, multi_gpu_testing=False, gpu_id=0, check_expected_results=False): ''' child_func = test_net parent_func = test_net_on_dataset ''' parent_func, child_func = get_eval_functions() ''' now it's clear. only workers are allocated with the range jobs, and thus if some process is calling the script with a range, them it is a worker, how smart ''' is_parent = ind_range is None ''' FROM test_net.py: run_inference( args, ind_range=args.range, (None) multi_gpu_testing=args.multi_gpu_testing, (True) check_expected_results=True)''' def result_getter(): '''for chile processes, they are called from the beginning of test_net script''' if is_parent: # Parent case: # In this case we're either running inference on the entire dataset in a # single process or (if multi_gpu_testing is True) using this process to # launch subprocesses that each run inference on a range of the dataset all_results = {} for i in range(len(cfg.TEST.DATASETS)): '''get the dataset, I think proposal_file is None''' dataset_name, proposal_file = get_inference_dataset(i) output_dir = args.output_dir results = parent_func(args, dataset_name, proposal_file, output_dir, multi_gpu=multi_gpu_testing) all_results.update(results) return all_results else: # Subprocess child case: # In this case test_net was called via subprocess.Popen to execute on a # range of inputs on a single dataset '''a cmd is writen in main process, and Popen used to execute the subprocess''' dataset_name, proposal_file = get_inference_dataset( 0, is_parent=False) output_dir = args.output_dir return child_func(args, dataset_name, proposal_file, output_dir, ind_range=ind_range, gpu_id=gpu_id) all_results = result_getter() if check_expected_results and is_parent: task_evaluation.check_expected_results(all_results, atol=cfg.EXPECTED_RESULTS_ATOL, rtol=cfg.EXPECTED_RESULTS_RTOL) task_evaluation.log_copy_paste_friendly_results(all_results) return all_results