Spaces:
Running
Running
File size: 3,240 Bytes
9bf4bd7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# Copyright (c) OpenMMLab. All rights reserved.
from argparse import ArgumentParser
from mmocr.apis.inferencers import MMOCRInferencer
def parse_args():
parser = ArgumentParser()
parser.add_argument(
'inputs', type=str, help='Input image file or folder path.')
parser.add_argument(
'--out-dir',
type=str,
default='results/',
help='Output directory of results.')
parser.add_argument(
'--det',
type=str,
default=None,
help='Pretrained text detection algorithm. It\'s the path to the '
'config file or the model name defined in metafile.')
parser.add_argument(
'--det-weights',
type=str,
default=None,
help='Path to the custom checkpoint file of the selected det model. '
'If it is not specified and "det" is a model name of metafile, the '
'weights will be loaded from metafile.')
parser.add_argument(
'--rec',
type=str,
default=None,
help='Pretrained text recognition algorithm. It\'s the path to the '
'config file or the model name defined in metafile.')
parser.add_argument(
'--rec-weights',
type=str,
default=None,
help='Path to the custom checkpoint file of the selected recog model. '
'If it is not specified and "rec" is a model name of metafile, the '
'weights will be loaded from metafile.')
parser.add_argument(
'--kie',
type=str,
default=None,
help='Pretrained key information extraction algorithm. It\'s the path'
'to the config file or the model name defined in metafile.')
parser.add_argument(
'--kie-weights',
type=str,
default=None,
help='Path to the custom checkpoint file of the selected kie model. '
'If it is not specified and "kie" is a model name of metafile, the '
'weights will be loaded from metafile.')
parser.add_argument(
'--device',
type=str,
default=None,
help='Device used for inference. '
'If not specified, the available device will be automatically used.')
parser.add_argument(
'--batch-size', type=int, default=1, help='Inference batch size.')
parser.add_argument(
'--show',
action='store_true',
help='Display the image in a popup window.')
parser.add_argument(
'--print-result',
action='store_true',
help='Whether to print the results.')
parser.add_argument(
'--save_pred',
action='store_true',
help='Save the inference results to out_dir.')
parser.add_argument(
'--save_vis',
action='store_true',
help='Save the visualization results to out_dir.')
call_args = vars(parser.parse_args())
init_kws = [
'det', 'det_weights', 'rec', 'rec_weights', 'kie', 'kie_weights',
'device'
]
init_args = {}
for init_kw in init_kws:
init_args[init_kw] = call_args.pop(init_kw)
return init_args, call_args
def main():
init_args, call_args = parse_args()
ocr = MMOCRInferencer(**init_args)
ocr(**call_args)
if __name__ == '__main__':
main()
|