args.py
4.81 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from __future__ import division, print_function
import numpy as np
import tensorflow as tf
import random
import math
from misc_utils import parse_anchors, read_class_names
from tfrecord_utils import TFRecordIterator
### Some paths
data_path = '../../data/'
train_file = data_path + 'train.tfrecord' # The path of the training txt file.
val_file = data_path + 'val.tfrecord' # The path of the validation txt file.
restore_path = data_path + 'darknet_weights/yolov3.ckpt' # The path of the weights to restore.
save_dir = '../../checkpoint/' # The directory of the weights to save.
### we are not using tensorboard logs in this code
log_dir = data_path + 'logs/' # The directory to store the tensorboard log files.
progress_log_path = data_path + 'progress.log' # The path to record the training progress.
anchor_path = data_path + 'yolo_anchors.txt' # The path of the anchor txt file.
class_name_path = data_path + 'classes.txt' # The path of the class names.
### Training releated numbers
batch_size = 10
img_size = [416, 416] # Images will be resized to `img_size` and fed to the network, size format: [width, height]
letterbox_resize = True # Whether to use the letterbox resize, i.e., keep the original aspect ratio in the resized image.
total_epoches = 20
train_evaluation_step = 10 # Evaluate on the training batch after some steps.
val_evaluation_epoch = 2 # Evaluate on the whole validation dataset after some epochs. Set to None to evaluate every epoch.
save_epoch = 5 # Save the model after some epochs.
batch_norm_decay = 0.99 # decay in bn ops
weight_decay = 5e-4 # l2 weight decay
global_step = 0 # used when resuming training
### tf.data parameters
num_threads = 10 # Number of threads for image processing used in tf.data pipeline.
prefetech_buffer = 5 # Prefetech_buffer used in tf.data pipeline.
### Learning rate and optimizer
optimizer_name = 'momentum' # Chosen from [sgd, momentum, adam, rmsprop]
save_optimizer = True # Whether to save the optimizer parameters into the checkpoint file.
learning_rate_init = 1e-4
lr_type = 'piecewise' # Chosen from [fixed, exponential, cosine_decay, cosine_decay_restart, piecewise]
lr_decay_epoch = 5 # Epochs after which learning rate decays. Int or float. Used when chosen `exponential` and `cosine_decay_restart` lr_type.
lr_decay_factor = 0.96 # The learning rate decay factor. Used when chosen `exponential` lr_type.
lr_lower_bound = 1e-6 # The minimum learning rate.
# only used in piecewise lr type
pw_boundaries = [30, 50] # epoch based boundaries
pw_values = [learning_rate_init, 3e-5, 1e-5]
### Load and finetune
# Choose the parts you want to restore the weights. List form.
# restore_include: None, restore_exclude: None => restore the whole model
# restore_include: None, restore_exclude: scope => restore the whole model except `scope`
# restore_include: scope1, restore_exclude: scope2 => if scope1 contains scope2, restore scope1 and not restore scope2 (scope1 - scope2)
# choise 1: only restore the darknet body
# restore_include = ['yolov3/darknet53_body']
# restore_exclude = None
# choise 2: restore all layers except the last 3 conv2d layers in 3 scale
restore_include = None
restore_exclude = ['yolov3/yolov3_head/Conv_14', 'yolov3/yolov3_head/Conv_6', 'yolov3/yolov3_head/Conv_22']
# Choose the parts you want to finetune. List form.
# Set to None to train the whole model.
update_part = ['yolov3/yolov3_head']
### other training strategies
multi_scale_train = True # Whether to apply multi-scale training strategy. Image size varies from [320, 320] to [640, 640] by default.
use_label_smooth = True # Whether to use class label smoothing strategy.
use_focal_loss = True # Whether to apply focal loss on the conf loss.
use_mix_up = True # Whether to use mix up data augmentation strategy.
use_warm_up = True # whether to use warm up strategy to prevent from gradient exploding.
warm_up_epoch = 2 # Warm up training epoches. Set to a larger value if gradient explodes.
### some constants in validation
# nms
nms_threshold = 0.45 # iou threshold in nms operation
score_threshold = 0.01 # threshold of the probability of the classes in nms operation, i.e. score = pred_confs * pred_probs. set lower for higher recall.
nms_topk = 150 # keep at most nms_topk outputs after nms
# mAP eval
eval_threshold = 0.5 # the iou threshold applied in mAP evaluation
use_voc_07_metric = False # whether to use voc 2007 evaluation metric, i.e. the 11-point metric
### parse some params
anchors = parse_anchors(anchor_path)
classes = read_class_names(class_name_path)
class_num = len(classes)
train_img_cnt = TFRecordIterator(train_file, 'GZIP').count()
val_img_cnt = TFRecordIterator(val_file, 'GZIP').count()
train_batch_num = int(math.ceil(float(train_img_cnt) / batch_size))
lr_decay_freq = int(train_batch_num * lr_decay_epoch)
pw_boundaries = [float(i) * train_batch_num + global_step for i in pw_boundaries]