-
Notifications
You must be signed in to change notification settings - Fork 0
/
decompose_and_ft.py
48 lines (44 loc) · 1.3 KB
/
decompose_and_ft.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
from tqdm import tqdm, trange
import argparse
from config import get_cfg_defaults
from model import model_factory
from engine.train import train_on_dataset
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-c",
"--config-file",
default="",
metavar="FILE",
help="path to config file",
type=str,
)
parser.add_argument(
"-r",
"--resume-file",
default=None,
metavar="FILE",
help="path to checkpoint from which to resume",
type=str,
)
parser.add_argument(
"opts",
help="Modify config options using the command-line",
default=None,
nargs=argparse.REMAINDER,
)
args = parser.parse_args()
cfg = get_cfg_defaults()
cfg.merge_from_file(args.config_file)
cfg.merge_from_list(args.opts)
cfg.freeze()
for r in trange(cfg.TRAIN.NUM_RUNS):
if cfg.MODEL.RUN_SPECIFIC_LOAD_PATH:
load_path = cfg.MODEL.LOAD_PATH.format(r)
else:
load_path = None
model = model_factory[cfg.MODEL.BACKBONE](cfg, load_path).cuda()
model = model.decompose(cfg)
if cfg.MODEL.FUSE_FOR_TRAIN:
model = model.fuse()
train_on_dataset(cfg, model, r, resume_path=args.resume_file)