mirror of
https://github.com/PaddlePaddle/PaddleOCR.git
synced 2025-11-12 16:13:40 +00:00
change infer args format from dict to list
This commit is contained in:
parent
eaf38b9b12
commit
359d81e585
24
paddleocr.py
24
paddleocr.py
@ -170,32 +170,20 @@ def maybe_download(model_storage_directory, url):
|
|||||||
def parse_args_whl(mMain=True):
|
def parse_args_whl(mMain=True):
|
||||||
import argparse
|
import argparse
|
||||||
extend_args_list = [
|
extend_args_list = [
|
||||||
{
|
['lang', str, 'ch'],
|
||||||
'name': 'lang',
|
['det', str2bool, True],
|
||||||
'type': str,
|
['rec', str2bool, True],
|
||||||
'default': 'ch'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'det',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': True
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'rec',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': True
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
for item in inference_args_list:
|
for item in inference_args_list:
|
||||||
if item['name'] == 'rec_char_dict_path':
|
if item[0] == 'rec_char_dict_path':
|
||||||
item['default'] = None
|
item[2] = None
|
||||||
inference_args_list.extend(extend_args_list)
|
inference_args_list.extend(extend_args_list)
|
||||||
if mMain:
|
if mMain:
|
||||||
return parse_args()
|
return parse_args()
|
||||||
else:
|
else:
|
||||||
inference_args_dict = {}
|
inference_args_dict = {}
|
||||||
for item in inference_args_list:
|
for item in inference_args_list:
|
||||||
inference_args_dict[item['name']] = item['default']
|
inference_args_dict[item[0]] = item[2]
|
||||||
return argparse.Namespace(**inference_args_dict)
|
return argparse.Namespace(**inference_args_dict)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -28,283 +28,75 @@ def str2bool(v):
|
|||||||
|
|
||||||
|
|
||||||
inference_args_list = [
|
inference_args_list = [
|
||||||
|
# name type defalue
|
||||||
# params for prediction engine
|
# params for prediction engine
|
||||||
{
|
['use_gpu', str2bool, True],
|
||||||
'name': 'use_gpu',
|
['use_tensorrt', str2bool, False],
|
||||||
'type': str2bool,
|
['use_fp16', str2bool, False],
|
||||||
'default': True
|
['use_pdserving', str2bool, False],
|
||||||
},
|
['use_mp', str2bool, False],
|
||||||
{
|
['enable_mkldnn', str2bool, False],
|
||||||
'name': 'ir_optim',
|
['ir_optim', str2bool, True],
|
||||||
'type': str2bool,
|
['total_process_num', int, 1],
|
||||||
'default': True
|
['process_id', int, 0],
|
||||||
},
|
['gpu_mem', int, 500],
|
||||||
{
|
|
||||||
'name': 'use_tensorrt',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': False
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'use_fp16',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': False
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'enable_mkldnn',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': False
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'use_pdserving',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': False
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'use_mp',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': False
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'total_process_num',
|
|
||||||
'type': int,
|
|
||||||
'default': 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'process_id',
|
|
||||||
'type': int,
|
|
||||||
'default': 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'gpu_mem',
|
|
||||||
'type': int,
|
|
||||||
'default': 500
|
|
||||||
},
|
|
||||||
# params for text detector
|
# params for text detector
|
||||||
{
|
['image_dir', str, None],
|
||||||
'name': 'image_dir',
|
['det_algorithm', str, 'DB'],
|
||||||
'type': str,
|
['det_model_dir', str, None],
|
||||||
'default': None
|
['det_limit_side_len', float, 960],
|
||||||
},
|
['det_limit_type', str, 'max'],
|
||||||
{
|
|
||||||
'name': 'det_algorithm',
|
|
||||||
'type': str,
|
|
||||||
'default': 'DB'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'det_model_dir',
|
|
||||||
'type': str,
|
|
||||||
'default': None
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'det_limit_side_len',
|
|
||||||
'type': float,
|
|
||||||
'default': 960
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'det_limit_type',
|
|
||||||
'type': str,
|
|
||||||
'default': 'max'
|
|
||||||
},
|
|
||||||
# DB parmas
|
# DB parmas
|
||||||
{
|
['det_db_thresh', float, 0.3],
|
||||||
'name': 'det_db_thresh',
|
['det_db_box_thresh', float, 0.5],
|
||||||
'type': float,
|
['det_db_unclip_ratio', float, 1.6],
|
||||||
'default': 0.3
|
['max_batch_size', int, 10],
|
||||||
},
|
['use_dilation', str2bool, False],
|
||||||
{
|
['det_db_score_mode', str, 'fast'],
|
||||||
'name': 'det_db_box_thresh',
|
|
||||||
'type': float,
|
|
||||||
'default': 0.5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'det_db_unclip_ratio',
|
|
||||||
'type': float,
|
|
||||||
'default': 1.6
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'max_batch_size',
|
|
||||||
'type': int,
|
|
||||||
'default': 10
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'use_dilation',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': False
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'det_db_score_mode',
|
|
||||||
'type': str,
|
|
||||||
'default': 'fast'
|
|
||||||
},
|
|
||||||
# EAST parmas
|
# EAST parmas
|
||||||
{
|
['det_east_score_thresh', float, 0.8],
|
||||||
'name': 'det_east_score_thresh',
|
['det_east_cover_thresh', float, 0.1],
|
||||||
'type': float,
|
['det_east_nms_thresh', float, 0.2],
|
||||||
'default': 0.8
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'det_east_cover_thresh',
|
|
||||||
'type': float,
|
|
||||||
'default': 0.1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'det_east_nms_thresh',
|
|
||||||
'type': float,
|
|
||||||
'default': 0.2
|
|
||||||
},
|
|
||||||
# SAST parmas
|
# SAST parmas
|
||||||
{
|
['det_sast_score_thresh', float, 0.5],
|
||||||
'name': 'det_sast_score_thresh',
|
['det_sast_nms_thresh', float, 0.2],
|
||||||
'type': float,
|
['det_sast_polygon', str2bool, False],
|
||||||
'default': 0.5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'det_sast_nms_thresh',
|
|
||||||
'type': float,
|
|
||||||
'default': 0.2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'det_sast_polygon',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': False
|
|
||||||
},
|
|
||||||
# params for text recognizer
|
# params for text recognizer
|
||||||
{
|
['rec_algorithm', str, 'CRNN'],
|
||||||
'name': 'rec_algorithm',
|
['rec_model_dir', str, None],
|
||||||
'type': str,
|
['rec_image_shape', str, '3, 32, 320'],
|
||||||
'default': 'CRNN'
|
['rec_char_type', str, "ch"],
|
||||||
},
|
['rec_batch_num', int, 6],
|
||||||
{
|
['max_text_length', int, 25],
|
||||||
'name': 'rec_model_dir',
|
['rec_char_dict_path', str, './ppocr/utils/ppocr_keys_v1.txt'],
|
||||||
'type': str,
|
['use_space_char', str2bool, True],
|
||||||
'default': None
|
['vis_font_path', str, './doc/fonts/simfang.ttf'],
|
||||||
},
|
['drop_score', float, 0.5],
|
||||||
{
|
|
||||||
'name': 'rec_image_shape',
|
|
||||||
'type': str,
|
|
||||||
'default': '3, 32, 320'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'rec_char_type',
|
|
||||||
'type': str,
|
|
||||||
'default': "ch"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'rec_batch_num',
|
|
||||||
'type': int,
|
|
||||||
'default': 6
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'max_text_length',
|
|
||||||
'type': int,
|
|
||||||
'default': 25
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'rec_char_dict_path',
|
|
||||||
'type': str,
|
|
||||||
'default': './ppocr/utils/ppocr_keys_v1.txt'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'use_space_char',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': True
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'vis_font_path',
|
|
||||||
'type': str,
|
|
||||||
'default': './doc/fonts/simfang.ttf'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'drop_score',
|
|
||||||
'type': float,
|
|
||||||
'default': 0.5
|
|
||||||
},
|
|
||||||
# params for e2e
|
# params for e2e
|
||||||
{
|
['e2e_algorithm', str, 'PGNet'],
|
||||||
'name': 'e2e_algorithm',
|
['e2e_model_dir', str, None],
|
||||||
'type': str,
|
['e2e_limit_side_len', float, 768],
|
||||||
'default': 'PGNet'
|
['e2e_limit_type', str, 'max'],
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'e2e_model_dir',
|
|
||||||
'type': str,
|
|
||||||
'default': None
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'e2e_limit_side_len',
|
|
||||||
'type': float,
|
|
||||||
'default': 768
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'e2e_limit_type',
|
|
||||||
'type': str,
|
|
||||||
'default': 'max'
|
|
||||||
},
|
|
||||||
# PGNet parmas
|
# PGNet parmas
|
||||||
{
|
['e2e_pgnet_score_thresh', float, 0.5],
|
||||||
'name': 'e2e_pgnet_score_thresh',
|
['e2e_char_dict_path', str, './ppocr/utils/ic15_dict.txt'],
|
||||||
'type': float,
|
['e2e_pgnet_valid_set', str, 'totaltext'],
|
||||||
'default': 0.5
|
['e2e_pgnet_polygon', str2bool, True],
|
||||||
},
|
['e2e_pgnet_mode', str, 'fast'],
|
||||||
{
|
|
||||||
'name': 'e2e_char_dict_path',
|
|
||||||
'type': str,
|
|
||||||
'default': './ppocr/utils/ic15_dict.txt'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'e2e_pgnet_valid_set',
|
|
||||||
'type': str,
|
|
||||||
'default': 'totaltext'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'e2e_pgnet_polygon',
|
|
||||||
'type': str2bool,
|
|
||||||
'default': True
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'e2e_pgnet_mode',
|
|
||||||
'type': str,
|
|
||||||
'default': 'fast'
|
|
||||||
},
|
|
||||||
# params for text classifier
|
# params for text classifier
|
||||||
{
|
['use_angle_cls', str2bool, False],
|
||||||
'name': 'use_angle_cls',
|
['cls_model_dir', str, None],
|
||||||
'type': str2bool,
|
['cls_image_shape', str, '3, 48, 192'],
|
||||||
'default': False
|
['label_list', list, ['0', '180']],
|
||||||
},
|
['cls_batch_num', int, 6],
|
||||||
{
|
['cls_thresh', float, 0.9],
|
||||||
'name': 'cls_model_dir',
|
|
||||||
'type': str,
|
|
||||||
'default': None
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'cls_image_shape',
|
|
||||||
'type': str,
|
|
||||||
'default': '3, 48, 192'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'label_list',
|
|
||||||
'type': list,
|
|
||||||
'default': ['0', '180']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'cls_batch_num',
|
|
||||||
'type': int,
|
|
||||||
'default': 6
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'cls_thresh',
|
|
||||||
'type': float,
|
|
||||||
'default': 0.9
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
for item in inference_args_list:
|
for item in inference_args_list:
|
||||||
parser.add_argument(
|
parser.add_argument('--' + item[0], type=item[1], default=item[2])
|
||||||
'--' + item['name'], type=item['type'], default=item['default'])
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user