File size: 3,750 Bytes
d7e58f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import os.path as osp
import sys
import datetime
from mmcv import Config as MMConfig

class Config(MMConfig):
    def __init__(self, cfg_dict=None, cfg_text=None, filename=None):
        super().__init__(cfg_dict, cfg_text, filename)

    def get_config_fromfile(self, config_path):
        self.config_path = config_path

        cfg, _ = MMConfig._file2dict(self.config_path)
        
        self.merge_from_dict(cfg)
        # #import ipdb;ipdb.set_trace()
        # self.__dict__.update(dict(cfg))
        # # update dir
        dir_dict = {}
        exp_name = 'exps62'
        time_str = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
        dir_dict['cur_dir'] = osp.dirname(os.path.abspath(__file__))
        dir_dict['root_dir'] = osp.join(dir_dict['cur_dir'], '..')
        dir_dict['output_dir'] = osp.join(dir_dict['root_dir'], exp_name)
        dir_dict['result_dir'] = osp.join(dir_dict['output_dir'], 'result')
        dir_dict['data_dir'] = osp.join(dir_dict['root_dir'], 'dataset')
        dir_dict['human_model_path'] = osp.join('data/body_models')
        self.merge_from_dict(dir_dict)
        # 
        # ## add some paths to the system root dir
        sys.path.insert(0, osp.join(self.root_dir, 'common'))
        sys.path.insert(0, osp.join(self.root_dir, 'united-perception_utils'))
        sys.path.insert(0, osp.join(self.cur_dir, 'humanbench_utils'))
        sys.path.insert(0, osp.join(self.cur_dir, 'dinov2_utils'))
        sys.path.insert(0, osp.join(self.cur_dir, 'lora_utils'))
        sys.path.insert(0, osp.join(self.cur_dir, 'vit_adapter_utils'))
        from util.dir import add_pypath
        # add_pypath(osp.join(self.data_dir))
        for dataset in os.listdir('datasets'):
            if dataset not in ['humandata.py', '__pycache__', 'dataset.py']:
                add_pypath(osp.join(self.root_dir, 'data', dataset))
        add_pypath('datasets')
        add_pypath(self.data_dir)

    def prepare_dirs(self, exp_name):
        time_str = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
        self.output_dir = osp.join(self.root_dir, f'{exp_name}_{time_str}')
        self.model_dir = osp.join(self.output_dir, 'model_dump')
        self.vis_dir = osp.join(self.output_dir, 'vis')
        self.log_dir = osp.join(self.output_dir, 'log')
        self.code_dir = osp.join(self.output_dir, 'code')
        self.result_dir = osp.join(self.output_dir.split('/')[:-1])
        from util.dir import make_folder
        make_folder(self.model_dir)
        make_folder(self.vis_dir)
        make_folder(self.log_dir)
        make_folder(self.code_dir)
        make_folder(self.result_dir)

        ## copy some code to log dir as a backup
        copy_files = [
            'main/train.py', 'main/test.py', 'common/base.py', 'main/OSX.py',
            'common/nets', 'main/OSX_WoDecoder.py', 'data/dataset.py',
            'data/MSCOCO/MSCOCO.py', 'data/AGORA/AGORA.py'
        ]
        for file in copy_files:
            os.system(f'cp -r {self.root_dir}/{file} {self.code_dir}')

    def update_test_config(self, testset, agora_benchmark, shapy_eval_split,
                           pretrained_model_path, use_cache):
        self.testset = testset
        self.agora_benchmark = agora_benchmark
        self.pretrained_model_path = pretrained_model_path
        self.shapy_eval_split = shapy_eval_split
        self.use_cache = use_cache

    def update_config(self, num_gpus, exp_name):
        self.num_gpus = num_gpus
        self.exp_name = exp_name

        self.prepare_dirs(self.exp_name)

        # Save
        cfg_save = MMConfig(self.__dict__)
        cfg_save.dump(osp.join(self.code_dir, 'config_base.py'))


cfg = Config()
cfg.get_config_fromfile('config/aios_smplx.py')