-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathuncertainty_training.py
73 lines (64 loc) · 2.96 KB
/
uncertainty_training.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
import logging
import os
from lib_yolo import yolov3, train, utils
def main():
config = {
'training': True, # edit: set to False for qualitative evaluation
'resume_training': True,
'resume_checkpoint': './checkpoints/pretraining/pretraining-125000', # edit
# 'resume_checkpoint': 'last', # edit: either filename or 'last' to resume a training
'priors': yolov3.ECP_9_PRIORS, # edit if not ECP dataset
'checkpoint_path': './checkpoints',
'tensorboard_path': './tensorboard',
'log_path': './log',
'ckp_max_to_keep': 75,
'checkpoint_interval': 5000,
'ign_thresh': 0.7,
'crop_img_size': [768, 1440, 3],
'full_img_size': [1024, 1920, 3], # edit if not ECP dataset
'train_steps': 500000,
'darknet53_weights': './darknet53.conv.74',
'batch_size': 2, # edit
'lr': 1e-5,
'run_id': 'epi_ale',
'cpu_thread_cnt': 24, # edit
'crop': True, # edit, random crops and rescaling reduces memory consumption and improves training
'freeze_darknet53': True, # if True the basenet weights are frozen during training
'inference_mode': False,
'aleatoric_loss': True,
'cls_cnt': 2, # edit if not ECP dataset
'implicit_background_class': True, # whether the label ids start at 1 or 0. True = 1, False = 0
'train': {
'file_pattern': os.path.expandvars('$HOME/data/ecp/tfrecords/ecp-day-train-*-of-*'), # edit
'num_shards': 20,
'shuffle_buffer_size': 2000,
'cache': False, # edit if you have enough memory, caches whole dataset in memory
},
'val': {
'file_pattern': os.path.expandvars('$HOME/data/ecp/tfrecords/ecp-day-val-*-of-*'), # edit
'num_shards': 4,
'shuffle_buffer_size': 10,
'cache': False, # edit if you have enough memory, caches whole dataset in memory
}
}
# Note regarding implicit background class:
# The tensorflow object detection API enforces that the class labels start with 1.
# The class 0 is reserved for an (implicit) background class. We support both file formats.
utils.add_file_logging(config, override_existing=True)
logging.info(json.dumps(config, indent=4, default=lambda x: str(x)))
model_cls = yolov3.bayesian_yolov3_aleatoric
if config['training']:
train.start(model_cls, config)
else:
config['inference_mode'] = True
config['resume_checkpoint'] = 'last'
config['thresh'] = 0.1 # filter out boxes with objectness score less than thresh
config['T'] = 20 # increase if you have enough memory
utils.qualitative_eval(model_cls, config)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO,
format='%(asctime)s, %(levelname)-8s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
)
main()