-
Notifications
You must be signed in to change notification settings - Fork 9
/
train_helper.py
57 lines (38 loc) · 1.76 KB
/
train_helper.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
from detectron2 import model_zoo
from detectron2.config import get_cfg
def configure_model(OUTPUT_DIR, base_config_file, base_weight_file=None, max_iter=20000, num_gpus=2, ims_per_batch=16,
learning_rate=0.00025, sizes=[32, 64, 128, 256, 512], aspect_ratios=[0.5, 1.0, 2.0]):
cfg = get_cfg()
cfg.OUTPUT_DIR = OUTPUT_DIR
cfg.merge_from_file(model_zoo.get_config_file(base_config_file))
cfg.DATASETS.TRAIN = ("road_damage_train",)
cfg.DATASETS.TEST = ()
# # for validation
cfg.DATASETS.TEST = ("road_damage_eval",)
cfg.TEST.EVAL_PERIOD = 5000
cfg.DATALOADER.NUM_WORKERS = ims_per_batch
if base_weight_file is not None:
cfg.MODEL.WEIGHTS = base_weight_file
cfg.SOLVER.IMS_PER_BATCH = ims_per_batch
cfg.SOLVER.REFERENCE_WORLD_SIZE = num_gpus
cfg.SOLVER.MAX_ITER = max_iter
cfg.SOLVER.BASE_LR = learning_rate
cfg.SOLVER.MOMENTUM = 0.9
cfg.SOLVER.NESTEROV = False
cfg.SOLVER.WEIGHT_DECAY = 0.0001
# The weight decay that's applied to parameters of normalization layers
# (typically the affine transformation)
cfg.SOLVER.WEIGHT_DECAY_NORM = 0.0
cfg.SOLVER.GAMMA = 0.1
# The iteration number to decrease learning rate by GAMMA.
cfg.SOLVER.STEPS = (30000,)
cfg.SOLVER.WARMUP_FACTOR = 1.0 / 1000
cfg.SOLVER.WARMUP_ITERS = 1000
cfg.SOLVER.WARMUP_METHOD = "linear"
# Save a checkpoint after every this number of iterations
cfg.SOLVER.CHECKPOINT_PERIOD = 5000
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 512 # 12500 # 4096 # faster, and good enough for this toy dataset (default: 512)
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 4
cfg.MODEL.ANCHOR_GENERATOR.SIZES = [sizes]
cfg.MODEL.ANCHOR_GENERATOR.ASPECT_RATIOS = [aspect_ratios]
return cfg