forked from open-mmlab/mmskeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
47 lines (37 loc) · 1.54 KB
/
demo.py
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
#!/usr/bin/env python
import argparse
import sys
import yaml
import torch
# torchlight
import torchlight
from torchlight import import_class
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Processor collection')
# region register processor yapf: disable
processors = dict()
processors['recognition'] = import_class('processor.recognition.REC_Processor')
processors['demo_old'] = import_class('processor.demo_old.Demo')
processors['demo'] = import_class('processor.demo_realtime.DemoRealtime')
processors['demo_offline'] = import_class('processor.demo_offline.DemoOffline')
#endregion yapf: enable
# add sub-parser
subparsers = parser.add_subparsers(dest='processor')
for k, p in processors.items():
subparsers.add_parser(k, parents=[p.get_parser()])
# read arguments
arg = parser.parse_args()
with open(arg.config, 'r') as f:
default_arg = yaml.load(f, Loader=yaml.FullLoader)
raw_weight_path = str(default_arg['weights'])
raw_weight = torch.load(raw_weight_path)
if set(raw_weight.keys()) == set({'meta', 'optimizer', 'state_dict'}): # convention of new model
converted_path = raw_weight_path.rsplit('.', maxsplit=1)[0] + '.pt'
torch.save(raw_weight['state_dict'], converted_path) # save the pt version of the model
default_arg['weights'] = str(converted_path)
with open(arg.config, "w") as f:
yaml.dump(default_arg, f)
# start
Processor = processors[arg.processor]
p = Processor(sys.argv[2:])
p.start()