-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (41 loc) · 1.35 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
import os
import argparse
# import some common detectron2 utilities
from detectron2.utils.logger import setup_logger
from detectron2.config import get_cfg
from detectron2.modeling import build_model
from detectron2.checkpoint import DetectionCheckpointer
from detectron2.engine import launch
# import custom code
import model
from trainner import train_model
from tester import test_model
from model.config import add_default_config
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--train', dest='train', action='store_true', help='train model before evaluation')
parser.add_argument('-cfg', '--config', dest='config', default='configs/custom.yaml')
args = parser.parse_args()
def main(args):
# Load config
setup_logger()
cfg = get_cfg()
cfg.set_new_allowed(True)
add_default_config(cfg)
config = args.config
cfg.merge_from_file(config)
# Prepare save folder
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
os.system(f'cp {config} {cfg.OUTPUT_DIR}/config.yaml')
# Load model and pre-trained weights
print('Load.... model')
model = build_model(cfg)
DetectionCheckpointer(model).load(cfg.MODEL.WEIGHTS)
print('Done...')
# Train
if args.train:
print('## Train model ##')
train_model(cfg, model)
# Test
test_model(cfg, model)
if __name__ == '__main__':
main(args)