MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / ArgsParser

Class ArgsParser

tools/utility.py:6–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5
6class ArgsParser(ArgumentParser):
7
8 def __init__(self):
9 super(ArgsParser,
10 self).__init__(formatter_class=RawDescriptionHelpFormatter)
11 self.add_argument('-c', '--config', help='configuration file to use')
12 self.add_argument('-o',
13 '--opt',
14 nargs='*',
15 help='set configuration options')
16 self.add_argument('--local_rank')
17 self.add_argument('--local-rank')
18
19 def parse_args(self, argv=None):
20 args = super(ArgsParser, self).parse_args(argv)
21 assert args.config is not None, 'Please specify --config=configure_file_path.'
22 args.opt = self._parse_opt(args.opt)
23 return args
24
25 def _parse_opt(self, opts):
26 config = {}
27 if not opts:
28 return config
29 for s in opts:
30 s = s.strip()
31 k, v = s.split('=', 1)
32 if '.' not in k:
33 config[k] = yaml.load(v, Loader=yaml.Loader)
34 else:
35 keys = k.split('.')
36 if keys[0] not in config:
37 config[keys[0]] = {}
38 cur = config[keys[0]]
39 for idx, key in enumerate(keys[1:]):
40 if idx == len(keys) - 2:
41 cur[key] = yaml.load(v, Loader=yaml.Loader)
42 else:
43 cur[key] = {}
44 cur = cur[key]
45 return config

Callers 13

infer_det.pyFile · 0.90
parse_argsFunction · 0.90
parse_argsFunction · 0.90
parse_argsFunction · 0.90
parse_argsFunction · 0.90
parse_argsFunction · 0.90
parse_argsFunction · 0.90
parse_argsFunction · 0.90
parse_argsFunction · 0.90
parse_argsFunction · 0.90
parse_argsFunction · 0.90
infer_rec.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected