-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.py
60 lines (48 loc) · 2.05 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
import argparse
import sys
import os
import shutil
import zipfile
import time
# torchlight
import torchlight
from torchlight import import_class
from processor.processor import init_seed
init_seed(0)
def save_src(target_path):
code_root = os.getcwd()
srczip = zipfile.ZipFile('./src.zip', 'w')
for root, dirnames, filenames in os.walk(code_root):
for filename in filenames:
if filename.split('\n')[0].split('.')[-1] == 'py':
srczip.write(os.path.join(root, filename).replace(code_root, '.'))
if filename.split('\n')[0].split('.')[-1] == 'yaml':
srczip.write(os.path.join(root, filename).replace(code_root, '.'))
if filename.split('\n')[0].split('.')[-1] == 'ipynb':
srczip.write(os.path.join(root, filename).replace(code_root, '.'))
srczip.close()
save_path = os.path.join(target_path, 'src_%s.zip' % time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime()))
shutil.copy('./src.zip', save_path)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Processor collection')
# region register processor yapf: disable
processors = dict()
processors['linear_evaluation'] = import_class('processor.linear_evaluation.LE_Processor')
processors['pretrain_crossclr_3views'] = import_class('processor.pretrain_crossclr_3views.CrosSCLR_3views_Processor')
processors['pretrain_crossclr'] = import_class('processor.pretrain_crossclr.CrosSCLR_Processor')
processors['pretrain_skeletonclr'] = import_class('processor.pretrain_skeletonclr.SkeletonCLR_Processor')
# 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()
# start
Processor = processors[arg.processor]
p = Processor(sys.argv[2:])
if p.arg.phase == 'train':
# save src
save_src(p.arg.work_dir)
p.start()