-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
55 lines (36 loc) · 1.6 KB
/
train.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
from detectron2.utils.logger import setup_logger
setup_logger()
from detectron2.data.datasets import register_coco_instances
from detectron2.engine import DefaultTrainer
import os
import pickle
from utlis import *
config_file_path = "COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml"
checkpoint_url = "COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml"
output_dir = "/content/drive/MyDrive/vstech/1"
num_classes = 1
device = "cuda"
train_dataset_name = "LP_train"
train_images_path = "/content/drive/MyDrive/image_test/train"
train_json_annot_path = "/content/drive/MyDrive/image_test/train.json"
test_dataset_name = "LP_test"
test_images_path = "/content/drive/MyDrive/image_test/test"
test_json_annot_path = "/content/drive/MyDrive/image_test/test.json"
cfg_save_path = "IS_COVER_MASK_cfg.pickle"
########################
register_coco_instances(name= train_dataset_name, metadata={},
json_file=train_json_annot_path,image_root=train_images_path)
register_coco_instances(name=test_dataset_name, metadata={},
json_file=test_json_annot_path,image_root=test_images_path)
# plot_samples(dataset_name=train_dataset_name,n=2)
#########################
def main():
cfg = get_train_cfg(config_file_path,checkpoint_url,train_dataset_name,test_dataset_name,num_classes,device,output_dir)
with open(cfg_save_path, 'wb') as f:
pickle.dump(cfg,f,protocol=pickle.HIGHEST_PROTOCOL)
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume=False)
trainer.train()
if __name__ == '__main__':
main()