def test_rcnn(cfg, dataset, image_set, root_path, dataset_path, ctx, prefix, epoch, vis, ignore_cache, shuffle, has_rpn, proposal, thresh, logger = None, output_path = None): pprint.pprint(cfg) logger.info('testing cfg:{}\n'.format(pprint.pformat(cfg))) if has_rpn: sym_instance = eval(cfg.symbol+'.'+cfg.symbol)() sym = sym_instance.get_symbol(cfg, is_train = False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path) roidb = imdb.get_roidb() else: assert False,'do not support' test_data = TestLoader(roidb,cfg,batch_size = len(ctx),shuffle = shuffle, has_rpn = has_rpn) arg_params, aux_params = load_param(prefix, epoch, process = True) data_shape_dict = dict(test_data.provide_data) sym_instance.infer_shape(data_shape_dict) data_names = [k[0] for k in test_data.provide_data] label_names = None max_data_shape = [('data', (1, 3, max([v[0] for v in cfg.SCALES]), max([int(v[1]//16*16) for v in cfg.SCALES])))] predictor = Predictor(sym, data_names, label_names, context = ctx, max_data_shapes = max_data_shape, provide_data = test_data.provide_data,provide_label = test_data.provide_label, arg_params = arg_params, aux_params = aux_params) pred_eval(predictor, test_data, imdb, cfg, vis = vis, ignore_cache = ignore_cache, thresh = thresh, logger = logger)
def test_rcnn(cfg, dataset, image_set, root_path, dataset_path, ctx, prefix, epoch, vis, ignore_cache, shuffle, has_rpn, proposal, thresh, logger=None, output_path=None): if not logger: assert False, 'require a logger' # print cfg pprint.pprint(cfg) logger.info('testing cfg:{}\n'.format(pprint.pformat(cfg))) # load symbol and testing data if has_rpn: sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() sym = sym_instance.get_symbol(cfg, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path) roidb = imdb.gt_roidb() else: sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() sym = sym_instance.get_symbol_rcnn(cfg, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path) gt_roidb = imdb.gt_roidb() roidb = eval('imdb.' + proposal + '_roidb')(gt_roidb) # get test data iter test_data = TestLoader(roidb, cfg, batch_size=len(ctx), shuffle=shuffle, has_rpn=has_rpn) # load model arg_params, aux_params = load_param(prefix, epoch, process=True) # infer shape data_shape_dict = dict(test_data.provide_data_single) sym_instance.infer_shape(data_shape_dict) sym_instance.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = None max_data_shape = [[('data', (1, 3, max([v[0] for v in cfg.SCALES]), max([v[1] for v in cfg.SCALES])))]] if not has_rpn: max_data_shape.append(('rois', (cfg.TEST.PROPOSAL_POST_NMS_TOP_N + 30, 5))) # create predictor predictor = Predictor(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) # start detection pred_eval(predictor, test_data, imdb, cfg, vis=vis, ignore_cache=ignore_cache, thresh=thresh, logger=logger)
def test_deeplab(network, dataset, image_set, root_path, dataset_path, ctx, prefix, epoch, vis, logger=None, output_path=None): if not logger: assert False, 'require a logger' # print config pprint.pprint(config) logger.info('testing config:{}\n'.format(pprint.pformat(config))) # load symbol and testing data sym = eval('get_' + network + '_test')(num_classes=config.dataset.NUM_CLASSES) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path) segdb = imdb.gt_segdb() # get test data iter test_data = TestDataLoader(segdb, batch_size=len(ctx)) # load model # arg_params, aux_params = load_param(prefix, epoch, convert=True, ctx=ctx, process=True) arg_params, aux_params = load_param(prefix, epoch, process=True) # infer shape data_shape_dict = dict(test_data.provide_data_single) arg_shape, _, aux_shape = sym.infer_shape(**data_shape_dict) arg_shape_dict = dict(zip(sym.list_arguments(), arg_shape)) aux_shape_dict = dict(zip(sym.list_auxiliary_states(), aux_shape)) # check parameters for k in sym.list_arguments(): if k in data_shape_dict or k in ['softmax_label']: continue assert k in arg_params, k + ' not initialized' assert arg_params[k].shape == arg_shape_dict[k], \ 'shape inconsistent for ' + k + ' inferred ' + str(arg_shape_dict[k]) + ' provided ' + str(arg_params[k].shape) for k in sym.list_auxiliary_states(): assert k in aux_params, k + ' not initialized' assert aux_params[k].shape == aux_shape_dict[k], \ 'shape inconsistent for ' + k + ' inferred ' + str(aux_shape_dict[k]) + ' provided ' + str(aux_params[k].shape) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = ['softmax_label'] max_data_shape = [[('data', (1, 3, max([v[0] for v in config.SCALES]), max([v[1] for v in config.SCALES])))]] # create predictor predictor = Predictor(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) # start detection pred_eval(predictor, test_data, imdb, vis=vis, logger=logger)
def test_rcnn(cfg, dataset, image_set, root_path, dataset_path, ctx, prefix, epoch, vis, ignore_cache, shuffle, has_rpn, proposal, thresh, logger=None, output_path=None): if not logger: assert False, 'require a logger' # print cfg pprint.pprint(cfg) logger.info('testing cfg:{}\n'.format(pprint.pformat(cfg))) # load symbol and testing data if has_rpn: sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() sym = sym_instance.get_symbol(cfg, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path) roidb = imdb.gt_roidb() else: sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() sym = sym_instance.get_symbol_rfcn(cfg, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path) gt_roidb = imdb.gt_roidb() roidb = eval('imdb.' + proposal + '_roidb')(gt_roidb) # get test data iter test_data = TestLoader(roidb, cfg, batch_size=len(ctx), shuffle=shuffle, has_rpn=has_rpn) # load model arg_params, aux_params = load_param(prefix, epoch, process=True) # infer shape data_shape_dict = dict(test_data.provide_data_single) sym_instance.infer_shape(data_shape_dict) sym_instance.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = None max_data_shape = [[('data', (1, 3, max([v[0] for v in cfg.SCALES]), max([v[1] for v in cfg.SCALES])))]] if not has_rpn: max_data_shape.append(('rois', (cfg.TEST.PROPOSAL_POST_NMS_TOP_N + 30, 5))) # create predictor predictor = Predictor(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) # start detection pred_eval(predictor, test_data, imdb, cfg, vis=vis, ignore_cache=ignore_cache, thresh=thresh, logger=logger)
def test_deeplab(): epoch = config.TEST.test_epoch ctx = [mx.gpu(int(i)) for i in config.gpus.split(',')] image_set = config.dataset.test_image_set root_path = config.dataset.root_path dataset = config.dataset.dataset dataset_path = config.dataset.dataset_path logger, final_output_path, experiments_path, _ = create_env(config.output_path, args.cfg, image_set) prefix = os.path.join(final_output_path, '..', '_'.join([iset for iset in config.dataset.image_set.split('+')]), config.TRAIN.model_prefix) # print config logger.info('testing config:{}\n'.format(pprint.pformat(config))) # load symbol and testing data sym_instance = eval(config.symbol + '.' + config.symbol)() sym = sym_instance.get_symbol(config, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=experiments_path) segdb = imdb.gt_segdb() #get test data iter batch_size = (config.TEST.BATCH_IMAGES) * len(ctx) mctx = ctx test_data = TestDataLoader(segdb, config=config, batch_size=batch_size,shuffle=False,ctx=mctx,has_label=imdb.has_label) # infer shape data_shape_dict = dict(test_data.provide_data_single) sym_instance.infer_shape(data_shape_dict) arg_params, aux_params = load_param(prefix, epoch, process=True) sym_instance.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = ['label'] max_data_shape = [[('data', (config.TEST.BATCH_IMAGES, 3, max([v[0] for v in config.SCALES]), max([v[1] for v in config.SCALES])))]] # create predictor predictor = Predictor(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) # start detection args.ignore_cache = True pred_eval(predictor, test_data, imdb, vis=args.vis, ignore_cache=args.ignore_cache, logger=logger)
def test_deeplab(): epoch = config.TEST.test_epoch ctx = [mx.gpu(int(i)) for i in config.gpus.split(',')] image_set = config.dataset.test_image_set root_path = config.dataset.root_path dataset = config.dataset.dataset dataset_path = config.dataset.dataset_path logger, final_output_path = create_logger(config.output_path, args.cfg, image_set) prefix = os.path.join(final_output_path, '..', '_'.join([iset for iset in config.dataset.image_set.split('+')]), config.TRAIN.model_prefix) # print config pprint.pprint(config) logger.info('testing config:{}\n'.format(pprint.pformat(config))) # load symbol and testing data sym_instance = eval(config.symbol + '.' + config.symbol)() sym = sym_instance.get_symbol(config, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=final_output_path) segdb = imdb.gt_segdb() # get test data iter test_data = TestDataLoader(segdb, config=config, batch_size=len(ctx)) # infer shape data_shape_dict = dict(test_data.provide_data_single) sym_instance.infer_shape(data_shape_dict) # load model and check parameters arg_params, aux_params = load_param(prefix, epoch, process=True) sym_instance.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = ['softmax_label'] max_data_shape = [[('data', (1, 3, max([v[0] for v in config.SCALES]), max([v[1] for v in config.SCALES])))]] # create predictor predictor = Predictor(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) # start detection pred_eval(predictor, test_data, imdb, vis=args.vis, ignore_cache=args.ignore_cache, logger=logger)
def test_fcis(config, dataset, image_set, root_path, dataset_path, ctx, prefix, epoch, vis, ignore_cache, shuffle, has_rpn, proposal, thresh, logger=None, output_path=None): if not logger: assert False, 'require a logger' # print config pprint.pprint(config) logger.info('testing config:{}\n'.format(pprint.pformat(config))) # load symbol and testing data if has_rpn: sym_instance = eval(config.symbol)() sym = sym_instance.get_symbol(config, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path, binary_thresh=config.BINARY_THRESH, mask_size=config.MASK_SIZE) sdsdb = imdb.gt_sdsdb() else: raise NotImplementedError # get test data iter test_data = TestLoader(sdsdb, config, batch_size=len(ctx), shuffle=shuffle, has_rpn=has_rpn) # load model arg_params, aux_params = load_param(prefix, epoch, process=True) # infer shape data_shape_dict = dict(test_data.provide_data_single) sym_instance.infer_shape(data_shape_dict) sym_instance.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = [] max_data_shape = [[('data', (1, 3, max([v[0] for v in config.SCALES]), max([v[1] for v in config.SCALES])))]] if not has_rpn: raise NotImplementedError() # create predictor predictor = Predictor(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) # start detection pred_eval(predictor, test_data, imdb, config, vis=vis, ignore_cache=ignore_cache, thresh=thresh, logger=logger)
def pred_eval_multiprocess( gpus, key_predictors, cur_predictors, test_datas, imdb, cfg, roidbs_seg_lens=roidbs_seg_lens, vis=False, thresh=1e-4, ignore_cache=True, ): start = time.time() if len(gpus) == 1: res = [ pred_eval(0, 0, key_predictors[0], cur_predictors[0], test_datas[0], roidbs[0], imdb, cfg, roidbs_seg_lens, vis, thresh, ignore_cache), ] else: print('multiple processes') pool = Pool(processes=len(gpus)) # , ctx=None) multiple_results = [ pool.apply_async(pred_eval, args=(i, gpu_id, key_predictors[i], cur_predictors[i], test_datas[i], roidbs[i], imdb, cfg, roidbs_seg_lens, vis, thresh, ignore_cache)) for i, gpu_id in enumerate(gpus) ] pool.close() pool.join() res = [res.get() for res in multiple_results] # imdb.evaluate_detections(all_boxes, output_dir) info_str = imdb.evaluate_detections_multiprocess(res, cfg.output_dir) end = time.time() print("test time: %0.4fs" % (end - start))
def run_fgfa(): def parse_args(): parser = argparse.ArgumentParser(description='Test a R-FCN network') # general # parser.add_argument('--cfg', help='experiment configure file name', required=False, type=str) parser.add_argument('--cfg', help='experiment configure file name', default='../experiments/fgfa_rfcn/cfgs/resnet_v1_101_flownet_imagenet_vid_rfcn_end2end_ohem.yaml', required=False, type=str) args, rest = parser.parse_known_args() update_config(args.cfg) # rcnn parser.add_argument('--orig_pred', help='True to get and evaluate original predictions. False to get predictions suited for REPP', action='store_true') parser.add_argument('--vis', help='turn on visualization', action='store_true') parser.add_argument('--ignore_cache', help='ignore cached results boxes', action='store_true') parser.add_argument('--thresh', help='valid detection threshold', default=1e-3, type=float) parser.add_argument('--shuffle', help='shuffle data on visualization', action='store_true') parser.add_argument('--dataset_path', help='path of the Imagenet VID dataset', type=str) args = parser.parse_args() return args args = parse_args() #curr_path = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, os.path.join('../external/mxnet', config.MXNET_VERSION)) import mxnet as mx from function.test_rcnn import test_rcnn, get_predictor from utils.create_logger import create_logger #ctx = [mx.gpu(int(i)) for i in config.gpus.split(',')] ctx = [mx.gpu(int(i)) for i in ['0'] ] print args # config.dataset.test_image_set = 'VID_val_videos_short' config.output_path = '.' + config.output_path logger, final_output_path = create_logger(config.output_path, args.cfg, config.dataset.test_image_set) # %% dataset = config.dataset.dataset image_set = config.dataset.test_image_set root_path = '../data' # config.dataset.root_path dataset_path = args.dataset_path motion_iou_path = './.' + config.dataset.motion_iou_path enable_detailed_eval = config.dataset.enable_detailed_eval output_path = final_output_path cfg = config pprint.pprint(cfg) logger.info('testing cfg:{}\n'.format(pprint.pformat(cfg))) # load symbol and testing data feat_sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() aggr_sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() feat_sym = feat_sym_instance.get_feat_symbol(cfg) aggr_sym = aggr_sym_instance.get_aggregation_symbol(cfg) imdb = eval(dataset)(image_set, root_path, dataset_path, motion_iou_path, result_path=output_path, enable_detailed_eval=enable_detailed_eval) roidb = imdb.gt_roidb() # %% # get test data iter # split roidbs gpu_num = len(ctx) roidbs = [[] for x in range(gpu_num)] roidbs_seg_lens = np.zeros(gpu_num, dtype=np.int) for x in roidb: gpu_id = np.argmin(roidbs_seg_lens) roidbs[gpu_id].append(x) roidbs_seg_lens[gpu_id] += x['frame_seg_len'] # get test data iter test_datas = [TestLoader(x, cfg, batch_size=1, shuffle=args.shuffle, has_rpn=config.TEST.HAS_RPN) for x in roidbs] # %% prefix = '../model/rfcn_fgfa_flownet_vid' epoch = 0 # load model arg_params, aux_params = load_param(prefix, epoch, process=True) # create predictor feat_predictors = [get_predictor(feat_sym, feat_sym_instance, cfg, arg_params, aux_params, test_datas[i], [ctx[i]]) for i in range(gpu_num)] aggr_predictors = [get_predictor(aggr_sym, aggr_sym_instance, cfg, arg_params, aux_params, test_datas[i], [ctx[i]]) for i in range(gpu_num)] # %% import pickle key_predictors = feat_predictors cur_predictors = aggr_predictors vis=args.vis ignore_cache=True thresh = args.thresh t = time.time() # store_filename = '/mnt/hdd/egocentric_results/ilsvrc/SELSA/res_{}_{}_raw_aug_score{}_op{}.pckl'.format( store_filename = '../predictions/res_{}_{}_raw_score{}_op{}.pckl'.format( config.dataset.test_image_set, args.cfg.split('/')[-1][:-5], thresh, args.orig_pred) print(store_filename) if os.path.isfile(store_filename): print('Loading results:', store_filename) res = pickle.load(open(store_filename, 'rb')) else: res = [pred_eval(0, key_predictors[0], cur_predictors[0], test_datas[0], imdb, cfg, vis, thresh, logger, ignore_cache),] print('Time: {:.2f}'.format(time.time()-t)) if not os.path.isdir('./predictions'): os.makedirs('./predictions/') pickle.dump(res, open(store_filename, 'wb')) print(' ** Transform FGFA predictions to REPP format') transform_selsa_results(store_filename, res, args.dataset_path) if args.orig_pred: info_str = imdb.evaluate_detections_multiprocess(res) print(info_str) return info_str
def test_net(args): # init config cfg_path = args.cfg update_config(cfg_path) # test parameters has_rpn = config.TEST.HAS_RPN if not has_rpn: raise NotImplementedError, "Network without RPN is not implemented" # load model model_path = args.model if '.params' not in model_path: model_path += ".params" assert osp.exists(model_path), ("Could not find model path %s" % (model_path)) arg_params, aux_params = load_param_file(model_path, process=True) print("\nLoaded model %s\n" % (model_path)) # gpu stuff ctx = [mx.gpu(int(i)) for i in config.gpus.split(',')] # load test dataset cfg_ds = config.dataset ds_name = cfg_ds.dataset ds_path = cfg_ds.dataset_path test_image_set = cfg_ds.test_image_set # logger logger, output_path = create_logger(config.output_path, args.cfg, config.dataset.test_image_set) logger.info('testing config:{}\n'.format(pprint.pformat(config))) if ds_name.lower() == "labelme": # from utils.load_data import load_labelme_gt_sdsdb imdb = labelme(test_image_set, ds_path, cfg_ds.root_path, mask_size=config.MASK_SIZE, binary_thresh=config.BINARY_THRESH, classes=cfg_ds.CLASSES) else: imdb = eval(ds_name)(test_image_set, cfg_ds.root_path, ds_path, result_path=output_path, binary_thresh=config.BINARY_THRESH, mask_size=config.MASK_SIZE) sdsdb = imdb.gt_sdsdb() # load network network = resnet_v1_101_fcis() sym = network.get_symbol(config, is_train=False) # get test data iter test_data = TestLoader(sdsdb, config, batch_size=len(ctx), shuffle=args.shuffle, has_rpn=has_rpn) # infer shape data_shape_dict = dict(test_data.provide_data_single) network.infer_shape(data_shape_dict) network.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = [] max_data_shape = [[('data', (1, 3, max([v[0] for v in config.SCALES]), max([v[1] for v in config.SCALES])))]] # # create predictor predictor = Predictor(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) # print(test_data.provide_data_single[0][1]) # print(test_data.provide_label) # start detection pred_eval(predictor, test_data, imdb, config, vis=args.vis, ignore_cache=args.ignore_cache, thresh=args.thresh, logger=logger)
def test_deeplab(): epoch = config.TEST.test_epoch ctx = [mx.gpu(int(i)) for i in config.gpus.split(',')] image_set = config.dataset.test_image_set_no_label root_path = config.dataset.root_path dataset = config.dataset.dataset dataset_path = config.dataset.dataset_path logger, final_output_path = create_logger(config.output_path, args.cfg, image_set) prefix = os.path.join( final_output_path, '..', '_'.join([iset for iset in config.dataset.image_set.split('+')]), config.TRAIN.model_prefix) # print config pprint.pprint(config) logger.info('testing config:{}\n'.format(pprint.pformat(config))) # load symbol and testing data sym_instance = eval(config.symbol + '.' + config.symbol)() sym = sym_instance.get_symbol(config, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=final_output_path) segdb = imdb.gt_segdb() # get test data iter if config.TEST.get('USE_EMSEMBLE', False): batch_size = (config.TEST.BATCH_IMAGES) mctx = [mx.cpu()] else: batch_size = (config.TEST.BATCH_IMAGES) * len(ctx) mctx = ctx # get test data iter test_data = TestDataLoader(segdb, config=config, batch_size=batch_size, shuffle=False, ctx=mctx, has_label=False) # infer shape data_shape_dict = dict(test_data.provide_data_single) sym_instance.infer_shape(data_shape_dict) use_emsemble = config.TEST.get('USE_EMSEMBLE', False) # when using the emsemble and the if not use_emsemble: # load model and check parameters arg_params, aux_params = load_param(prefix, epoch, process=True) sym_instance.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = ['label'] max_data_shape = [[('data', (1, 3, max([v[0] for v in config.SCALES]), max([v[1] for v in config.SCALES])))]] # create predictor predictor = Predictor(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) else: num_emsemble = config.TEST.get('NUM_EMSEMBLE') arg_params_list, aux_params_list = load_param_emsemble(prefix, epoch, num_emsemble, process=True) for arg_params, aux_params in zip(arg_params_list, aux_params_list): sym_instance.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = ['label'] max_data_shape = [[('data', (1, 3, max([v[0] for v in config.SCALES]), max([v[1] for v in config.SCALES])))]] predictor = Predictor_Emsemble(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params_list=arg_params_list, aux_params_list=aux_params_list) # start detection pred_eval(predictor, test_data, imdb, vis=args.vis, ignore_cache=args.ignore_cache, logger=logger, has_label=False)
def test_rcnn(cfg, dataset, image_set, root_path, dataset_path, ctx, prefix, epoch, vis, ignore_cache, shuffle, has_rpn, proposal, thresh, logger=None, output_path=None, nms_dets=None, is_docker=False): if not logger: assert False, 'require a logger' # print cfg #pprint.pprint(cfg) #logger.info('testing cfg:{}\n'.format(pprint.pformat(cfg))) #leonid: added to support ; for multi-dataset listing - this is a temp solution allowing just one DB in test datasets = dataset.split(';') dataset_paths = dataset_path.split(';') imagesets = image_set.split(';') output_paths = output_path.split(';') categ_index_offs = 20 #TODO: remove for dataset, dataset_path, image_set, output_path in zip( datasets, dataset_paths, imagesets, output_paths): if len(image_set.strip()) <= 0: continue if 'classes_list_fname' not in cfg.dataset: classes_list_fname = '' else: classes_list_fname = cfg.dataset.classes_list_fname # load symbol and testing data if has_rpn: sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() sym = sym_instance.get_symbol(cfg, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path, classes_list_fname=classes_list_fname, categ_index_offs=categ_index_offs) roidb = imdb.gt_roidb() else: sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() sym = sym_instance.get_symbol_rcnn(cfg, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path) gt_roidb = imdb.gt_roidb() roidb = eval('imdb.' + proposal + '_roidb')(gt_roidb) categ_index_offs += imdb.num_classes # get test data iter test_data = TestLoader(roidb, cfg, batch_size=len(ctx), shuffle=shuffle, has_rpn=has_rpn) if not is_docker: # load model arg_params, aux_params = load_param(prefix, epoch, process=True) # infer shape data_shape_dict = dict(test_data.provide_data_single) sym_instance.infer_shape(data_shape_dict) sym_instance.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = None max_data_shape = [[('data', (1, 3, max([v[0] for v in cfg.SCALES]), max([v[1] for v in cfg.SCALES])))]] if not has_rpn: max_data_shape.append( ('rois', (cfg.TEST.PROPOSAL_POST_NMS_TOP_N + 30, 5))) # create predictor predictor = Predictor(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) #make sure imdb and detector have the same number of classes #imdb.num_classes=min(imdb.num_classes,cfg.dataset.NUM_CLASSES) # JS, March 2019: the JES dataset class produces num_classes = number of foreground classes, while the tester assumes this includes the background. imdb.num_classes = cfg.dataset.NUM_CLASSES else: predictor = None # start detection pred_eval(predictor, test_data, imdb, cfg, vis=vis, ignore_cache=ignore_cache, thresh=thresh, logger=logger, nms_dets=nms_dets)
def test_deepim(): config.TRAIN.MASK_SYN = False if args.vis or args.vis_video or args.vis_video_zoom: config.TEST.VISUALIZE = True config.TEST.FAST_TEST = False epoch = config.TEST.test_epoch ctx = [mx.gpu(int(i)) for i in args.gpus.split(",")] image_set = config.dataset.test_image_set root_path = config.dataset.root_path dataset = config.dataset.dataset.split("+")[0] dataset_path = config.dataset.dataset_path new_args_name = args.cfg logger, final_output_path = create_logger( config.output_path, new_args_name, image_set ) prefix = os.path.join( final_output_path, "..", "_".join([iset for iset in config.dataset.image_set.split("+")]), config.TRAIN.model_prefix, ) pprint.pprint(config) logger.info("testing config:{}\n".format(pprint.pformat(config))) # load symbol and testing data sym_instance = eval(config.symbol + "." + config.symbol)() sym = sym_instance.get_symbol(config, is_train=False) if config.dataset.dataset.startswith("ModelNet"): imdb_test = eval(dataset)( config, image_set + config.dataset.class_name[0].split("/")[-1], root_path, dataset_path, class_name=config.dataset.class_name[0], result_path=final_output_path, ) print(imdb_test) pairdbs = [ load_gt_pairdb( config, dataset, image_set + class_name.split("/")[-1], config.dataset.root_path, config.dataset.dataset_path, class_name=class_name, result_path=final_output_path, ) for class_name in config.dataset.class_name ] pairdb = merge_pairdb(pairdbs) else: imdb_test = eval(dataset)( config, image_set + config.dataset.class_name[0], root_path, dataset_path, class_name=config.dataset.class_name[0], result_path=final_output_path, ) print(imdb_test) pairdbs = [ load_gt_pairdb( config, dataset, image_set + class_name, config.dataset.root_path, config.dataset.dataset_path, class_name=class_name, result_path=final_output_path, ) for class_name in config.dataset.class_name ] pairdb = merge_pairdb(pairdbs) # get test data iter test_data = TestDataLoader(pairdb, config=config, batch_size=len(ctx)) # infer shape data_shape_dict = dict(test_data.provide_data_single) sym_instance.infer_shape(data_shape_dict) # load model and check parameters arg_params, aux_params = load_param(prefix, epoch, process=True) sym_instance.check_parameter_shapes( arg_params, aux_params, data_shape_dict, is_train=False ) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = None max_data_shape = [ [ ( "data", ( 1, 3, max([v[0] for v in config.SCALES]), max([v[1] for v in config.SCALES]), ), ) ] ] # create predictor predictor = Predictor( config, sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params, ) # start detection pred_eval( config, predictor, test_data, imdb_test, vis=args.vis, ignore_cache=args.ignore_cache, logger=logger, pairdb=pairdb, ) print(args.cfg, config.TEST.test_epoch)
def test_deepim(): config.TRAIN.MASK_SYN = False if args.vis or args.vis_video or args.vis_video_zoom: config.TEST.VISUALIZE = True config.TEST.FAST_TEST = False if args.iter_test: config.TEST.test_iter = 5 if args.refine: config.TEST.test_iter = 1 if args.skip_flow: config.network.FLOW_I2R = False config.network.FLOW_R2I = False config.train_iter0.FLOW_I2R = False config.train_iter0.FLOW_R2I = False config.train_iter1.FLOW_I2R = False config.train_iter1.FLOW_R2I = False config.train_iter2.FLOW_I2R = False config.train_iter2.FLOW_R2I = False config.train_iter3.FLOW_I2R = False config.train_iter3.FLOW_R2I = False epoch = config.TEST.test_epoch ctx = [mx.gpu(int(i)) for i in args.gpus.split(',')] if len(ctx) != config.NUM_GPUS: print("********** WARNING: length of context doesn't match num_gpus set in config, {} vs. {} **********".\ format(len(ctx), config.NUM_GPUS)) image_set = config.dataset.test_image_set root_path = config.dataset.root_path dataset = config.dataset.dataset.split('+')[0] dataset_path = config.dataset.dataset_path if not os.path.basename(args.cfg).split('.')[0].endswith('temp'): new_args_name = os.path.basename( args.cfg).split('.')[0] + '_{}gpus.yaml'.format(config.NUM_GPUS) else: new_args_name = args.cfg if config.TEST.VISUALIZE or args.temp: logger, final_output_path = create_logger(config.output_path, new_args_name, image_set, True) else: logger, final_output_path = create_logger(config.output_path, new_args_name, image_set) prefix = os.path.join( final_output_path, '..', '_'.join([iset for iset in config.dataset.image_set.split('+')]), config.TRAIN.model_prefix) pprint.pprint(config) logger.info('testing config:{}\n'.format(pprint.pformat(config))) # load symbol and testing data sym_instance = eval(config.symbol + '.' + config.symbol)() sym = sym_instance.get_symbol(config, is_train=False) if config.dataset.dataset.startswith('ModelNet'): imdb_test = eval(dataset)(config, image_set + config.dataset.class_name[0].split('/')[-1], root_path, dataset_path, class_name=config.dataset.class_name[0], result_path=final_output_path) print(imdb_test) pairdbs = [ load_gt_pairdb(config, dataset, image_set + class_name.split('/')[-1], config.dataset.root_path, config.dataset.dataset_path, class_name=class_name, result_path=final_output_path) for class_name in config.dataset.class_name ] pairdb = merge_pairdb(pairdbs) else: imdb_test = eval(dataset)(config, image_set + config.dataset.class_name[0], root_path, dataset_path, class_name=config.dataset.class_name[0], result_path=final_output_path) print(imdb_test) pairdbs = [ load_gt_pairdb(config, dataset, image_set + class_name, config.dataset.root_path, config.dataset.dataset_path, class_name=class_name, result_path=final_output_path) for class_name in config.dataset.class_name ] pairdb = merge_pairdb(pairdbs) # get test data iter test_data = TestDataLoader(pairdb, config=config, batch_size=len(ctx)) # infer shape data_shape_dict = dict(test_data.provide_data_single) sym_instance.infer_shape(data_shape_dict) # load model and check parameters arg_params, aux_params = load_param(prefix, epoch, process=True) sym_instance.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = None max_data_shape = [[('data', (1, 3, max([v[0] for v in config.SCALES]), max([v[1] for v in config.SCALES])))]] # create predictor predictor = Predictor(config, sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) # start detection pred_eval(config, predictor, test_data, imdb_test, vis=args.vis, ignore_cache=args.ignore_cache, logger=logger, pairdb=pairdb) print(args.cfg, config.TEST.test_epoch)
def test_rcnn(cfg, dataset, image_set, root_path, dataset_path, ctx, prefix, epoch, vis, ignore_cache, shuffle, has_rpn, proposal, thresh, logger=None, output_path=None): if not logger: assert False, 'require a logger' # print cfg pprint.pprint(cfg) logger.info('testing cfg:{}\n'.format(pprint.pformat(cfg))) # load symbol and testing data if has_rpn: sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() sym = sym_instance.get_symbol(cfg, is_train=False) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path) roidb = imdb.gt_roidb() # print (roidb) # roidb = test_load_gt_roidb(image_set, cfg.dataset.dataset_path) else: sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() sym = sym_instance.get_symbol_rcnn(cfg, is_train=False) rpn_path = cfg.dataset.proposal_cache imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path, rpn_path=rpn_path) gt_roidb = imdb.gt_roidb() roidb = eval('imdb.' + proposal + '_roidb')(gt_roidb, top_roi=cfg.TEST.TOP_ROIS) # get test data iter test_data = TestLoader(roidb, cfg, batch_size=len(ctx), shuffle=shuffle, has_rpn=has_rpn) # load model arg_params, aux_params = load_param(prefix, epoch, process=True) # infer shape data_shape_dict = dict(test_data.provide_data_single) #sym_instance.infer_shape(data_shape_dict) #sym_instance.check_parameter_shapes(arg_params, aux_params, data_shape_dict, is_train=False) # decide maximum shape data_names = [k[0] for k in test_data.provide_data_single] label_names = None #max_data_shape = [[('data', (1, 3, max([v[0] for v in cfg.SCALES]), max([v[1] for v in cfg.SCALES])))]] max_height = max([v[0] for v in cfg.SCALES]) max_width = max([v[1] for v in cfg.SCALES]) if cfg.network.IMAGE_STRIDE > 0: max_height = max_height + cfg.network.IMAGE_STRIDE - max_height % cfg.network.IMAGE_STRIDE max_width = max_width + cfg.network.IMAGE_STRIDE - max_width % cfg.network.IMAGE_STRIDE max_data_shape = [('data', (cfg.TRAIN.BATCH_IMAGES, 3, max_height, max_width))] if not has_rpn: #max_data_shape.append(('rois', (cfg.TEST.PROPOSAL_POST_NMS_TOP_N + 30, 5))) if cfg.network.ROIDispatch: max_data_shape.append( ('rois_0', (1, cfg.TEST.PROPOSAL_POST_NMS_TOP_N / 4, 5))) max_data_shape.append( ('rois_1', (1, cfg.TEST.PROPOSAL_POST_NMS_TOP_N / 4, 5))) max_data_shape.append( ('rois_2', (1, cfg.TEST.PROPOSAL_POST_NMS_TOP_N / 4, 5))) max_data_shape.append( ('rois_3', (1, cfg.TEST.PROPOSAL_POST_NMS_TOP_N / 4, 5))) max_data_shape = [max_data_shape] # create predictor #test_data.provide_label predictor = Predictor(sym, data_names, label_names, context=ctx, max_data_shapes=max_data_shape, provide_data=test_data.provide_data, provide_label=test_data.provide_label, arg_params=arg_params, aux_params=aux_params) # start detection # print ('start detection') # print (test_data) pred_eval(predictor, test_data, imdb, cfg, vis=vis, ignore_cache=ignore_cache, thresh=thresh, logger=logger)
def test_rcnn_(cfg, dataset, image_set, root_path, dataset_path, ctx, prefix, epoch, vis, show_gt, ignore_cache, shuffle, has_rpn, proposal, thresh, logger=None, output_path=None): if not logger: assert False, 'require a logger' # print cfg pprint.pprint(cfg) logger.info('testing cfg:{}\n'.format(pprint.pformat(cfg))) # load symbol and testing data sym_instance = eval(cfg.symbol + '.' + cfg.symbol)() sym = sym_instance.get_test_symbol(cfg) imdb = eval(dataset)(image_set, root_path, dataset_path, result_path=output_path) roidb = imdb.gt_roidb() # get test data iter test_data = TestLoader(roidb, cfg, batch_size=1, shuffle=shuffle, has_rpn=has_rpn) # load model # data_shape_dict = dict(test_data.provide_data_single + test_data.provide_label_single) data_shape_dict = dict(test_data.provide_data_single) pprint.pprint(data_shape_dict) sym_instance.infer_shape(data_shape_dict) arg_params, aux_params = load_param(prefix, epoch, process=True) # sym_instance.init_weight(cfg, arg_params, aux_params) # create predictor predictor = get_predictor(sym, sym_instance, cfg, arg_params, aux_params, test_data, ctx) # start detection #pred_eval(0, key_predictors[0], cur_predictors[0], test_datas[0], imdb, cfg, vis=vis, ignore_cache=ignore_cache, thresh=thresh, logger=logger) pred_eval(predictor, test_data, imdb, cfg, vis=vis, ignore_cache=ignore_cache, thresh=thresh, logger=logger)