-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrain_instance_seg_solov2.py
57 lines (36 loc) · 1.46 KB
/
train_instance_seg_solov2.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 sys
from os.path import exists, join, basename, splitext
project_name=os.path.abspath(os.getcwd())
mmdetection_dir = os.path.join(project_name, "mmdetection")
mmcv_dir = os.path.join(project_name, "mmcv")
sys.path.insert(0,project_name)
#sys.path.insert(1,mmcv_dir)
sys.path.append(mmdetection_dir)
import mmcv
from mmcv import Config
from mmdet.apis import set_random_seed
cfg = Config.fromfile('configs/solov2/solov2_r50_fpn_1x_coco.py')
cfg.work_dir = './tutorial_exps/solov2'
cfg.load_from = None
cfg.seed = 1321
# set_random_seed(0, deterministic=False)
cfg.gpu_ids = range(1)
cfg.evaluation.interval = 2
# We can set the checkpoint saving interval to reduce the storage cost
cfg.checkpoint_config.interval = 5
#print(f'Config:\n{cfg.pretty_text}')
# with open("myconfigs/solov2_r50_fpn_1x_coco.py","w+") as f:
# f.writelines(cfg.pretty_text)
if __name__ == '__main__':
from mmdet.datasets import build_dataset
from mmdet.models import build_detector
from train.train import train_detector
cfg = Config.fromfile("myconfigs/solov2_r50_fpn_1x_coco.py")
print(f'Config:\n{cfg.pretty_text}')
datasets = [build_dataset(cfg.data.train)]
model = build_detector(
cfg.model, train_cfg=cfg.get('train_cfg'), test_cfg=cfg.get('test_cfg'))
model.CLASSES = ('balloon', )
mmcv.mkdir_or_exist(os.path.abspath(cfg.work_dir))
train_detector(model, datasets, cfg, distributed=False, validate=True)