-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
78 lines (64 loc) · 2.14 KB
/
utils.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import torch
from mmcv.cnn import NORM_LAYERS
from mmcv.runner import TextLoggerHook
from todd.base import Config, DebugMode, get_logger
class Debug:
CUSTOM = DebugMode()
TRAIN_WITH_VAL_DATASET = DebugMode()
LESS_DATA = DebugMode()
LESS_BBOXES = DebugMode()
CPU = DebugMode()
SMALLER_BATCH_SIZE = DebugMode()
FREQUENT_EVAL = DebugMode()
def odps_init():
logger = get_logger()
logger.debug("ODPS initializing.")
def _dump_log(*args, **kwargs):
return
TextLoggerHook._dump_log = _dump_log
if not os.path.lexists('data'):
os.symlink('/data/oss_bucket_0', 'data')
if not os.path.lexists('pretrained'):
os.symlink('/data/oss_bucket_0/ckpts', 'pretrained')
if not os.path.lexists('work_dirs'):
os.symlink('/data/oss_bucket_0/work_dirs', 'work_dirs')
logger.debug(f"ODPS initialization done with {os.listdir('.')}.")
def debug_init(debug: bool, cfg: Config):
if torch.cuda.is_available():
if debug:
Debug.LESS_DATA = True
assert not Debug.CPU
else:
Debug.TRAIN_WITH_VAL_DATASET = True
Debug.LESS_DATA = True
Debug.LESS_BBOXES = True
Debug.CPU = True
Debug.SMALLER_BATCH_SIZE = True
Debug.FREQUENT_EVAL = True
if (
Debug.TRAIN_WITH_VAL_DATASET and 'data' in cfg and 'train' in cfg.data
and 'val' in cfg.data
):
data_train = cfg.data.train
data_val = cfg.data.val
if 'dataset' in data_train:
data_train = data_train.dataset
if 'dataset' in data_val:
data_val = data_val.dataset
data_val = { # yapf: disable
k: v for k, v in data_val.items()
if k in ['ann_file', 'img_prefix', 'proposal_file']
}
data_train.update(data_val)
if Debug.CPU:
cfg.fp16 = None
NORM_LAYERS.register_module(
'SyncBN',
force=True,
module=NORM_LAYERS.get('BN'),
)
if Debug.SMALLER_BATCH_SIZE and 'data' in cfg:
cfg.data.samples_per_gpu = 2
if Debug.FREQUENT_EVAL and 'evaluation' in cfg:
cfg.evaluation.interval = 1