def create_predictor(args, mode, logger):
    if (mode == 'det'):
        model_dir = args.det_model_dir
    elif (mode == 'cls'):
        model_dir = args.cls_model_dir
    elif (mode == 'rec'):
        model_dir = args.rec_model_dir
    else:
        model_dir = args.e2e_model_dir
    if (model_dir is None):
        logger.info('not find {} model file path {}'.format(mode, model_dir))
        sys.exit(0)
    model_file_path = (model_dir + '/inference.pdmodel')
    params_file_path = (model_dir + '/inference.pdiparams')
    if (not os.path.exists(model_file_path)):
        logger.info('not find model file path {}'.format(model_file_path))
        sys.exit(0)
    if (not os.path.exists(params_file_path)):
        logger.info('not find params file path {}'.format(params_file_path))
        sys.exit(0)
    config = inference.Config(model_file_path, params_file_path)
    if args.use_gpu:
        config.enable_use_gpu(args.gpu_mem, 0)
        if args.use_tensorrt:
            config.enable_tensorrt_engine(precision_mode=(inference.PrecisionType.Half if args.use_fp16 else inference.PrecisionType.Float32), max_batch_size=args.max_batch_size)
    else:
        config.disable_gpu()
        cpu_threads = (args.cpu_threads if hasattr(args, 'cpu_threads') else 10)
        config.set_cpu_math_library_num_threads(cpu_threads)
        if args.enable_mkldnn:
            config.set_mkldnn_cache_capacity(10)
            config.enable_mkldnn()
    config.enable_memory_optim()
    config.disable_glog_info()
    config.delete_pass('conv_transpose_eltwiseadd_bn_fuse_pass')
    config.switch_use_feed_fetch_ops(False)
    predictor = inference.create_predictor(config)
    input_names = predictor.get_input_names()
    for name in input_names:
        input_tensor = predictor.get_input_handle(name)
    output_names = predictor.get_output_names()
    output_tensors = []
    for output_name in output_names:
        output_tensor = predictor.get_output_handle(output_name)
        output_tensors.append(output_tensor)
    return (predictor, input_tensor, output_tensors)
def create_predictor(args, mode, logger):
    if (mode == 'det'):
        model_dir = args.det_model_dir
    elif (mode == 'cls'):
        model_dir = args.cls_model_dir
    elif (mode == 'rec'):
        model_dir = args.rec_model_dir
    else:
        model_dir = args.e2e_model_dir
    if (model_dir is None):
        logger.info('not find {} model file path {}'.format(mode, model_dir))
        sys.exit(0)
    model_file_path = (model_dir + '/inference.pdmodel')
    params_file_path = (model_dir + '/inference.pdiparams')
    if (not os.path.exists(model_file_path)):
        logger.info('not find model file path {}'.format(model_file_path))
        sys.exit(0)
    if (not os.path.exists(params_file_path)):
        logger.info('not find params file path {}'.format(params_file_path))
        sys.exit(0)
    config = inference.Config(model_file_path, params_file_path)
    if args.use_gpu:
        config.enable_use_gpu(args.gpu_mem, 0)
        if args.use_tensorrt:
            config.enable_tensorrt_engine(precision_mode=(inference.PrecisionType.Half if args.use_fp16 else inference.PrecisionType.Float32), max_batch_size=args.max_batch_size)
    else:
        config.disable_gpu()
        cpu_threads = (args.cpu_threads if hasattr(args, 'cpu_threads') else 10)
        config.set_cpu_math_library_num_threads(cpu_threads)
        if args.enable_mkldnn:
            config.set_mkldnn_cache_capacity(10)
            config.enable_mkldnn()
    config.enable_memory_optim()
    config.disable_glog_info()
    config.delete_pass('conv_transpose_eltwiseadd_bn_fuse_pass')
    config.switch_use_feed_fetch_ops(False)
    predictor = inference.create_predictor(config)
    input_names = predictor.get_input_names()
    for name in input_names:
        input_tensor = predictor.get_input_handle(name)
    output_names = predictor.get_output_names()
    output_tensors = []
    for output_name in output_names:
        output_tensor = predictor.get_output_handle(output_name)
        output_tensors.append(output_tensor)
    return (predictor, input_tensor, output_tensors)