From 43230c48bf206cc8f3d409eb97e95965893d8aa1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 18 Aug 2019 02:02:04 +0200 Subject: [PATCH] updates --- train.py | 74 +++++++++++++++++++++++++------------------------- utils/utils.py | 3 +- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/train.py b/train.py index d62aa8a4..ceea5782 100644 --- a/train.py +++ b/train.py @@ -33,45 +33,45 @@ except: # 0.268 0.268 0.178 0.240 4.36 1.104 5.596 0.2087 14.47 2.599 16.27 2.406 0.4114 0.001585 -4 0.950 0.000524 # hc # 0.161 0.327 0.190 0.193 7.82 1.153 4.062 0.1845 24.28 3.05 20.93 2.842 0.2759 0.001357 -4 0.916 0.000572 # hd 0.438 mAP @ epoch 100 -# Hyperparameters (j-series, 50.5 mAP yolov3-320) evolved by @ktian08 https://github.com/ultralytics/yolov3/issues/310 -hyp = {'giou': 1.582, # giou loss gain - 'xy': 4.688, # xy loss gain - 'wh': 0.1857, # wh loss gain - 'cls': 27.76, # cls loss gain (CE=~1.0, uCE=~20, uBCE=~200,~30) - 'cls_pw': 1.446, # cls BCELoss positive_weight - 'obj': 21.35, # obj loss gain - 'obj_pw': 3.941, # obj BCELoss positive_weight - 'iou_t': 0.2635, # iou training threshold - 'lr0': 0.002324, # initial learning rate - 'lrf': -4., # final LambdaLR learning rate = lr0 * (10 ** lrf) - 'momentum': 0.97, # SGD momentum - 'weight_decay': 0.0004569, # optimizer weight decay - 'hsv_s': 0.5703, # image HSV-Saturation augmentation (fraction) - 'hsv_v': 0.3174, # image HSV-Value augmentation (fraction) - 'degrees': 1.113, # image rotation (+/- deg) - 'translate': 0.06797, # image translation (+/- fraction) - 'scale': 0.1059, # image scale (+/- gain) - 'shear': 0.5768} # image shear (+/- deg) - -# # Hyperparameters (i-series) -# hyp = {'giou': 1.43, # giou loss gain +# # Hyperparameters (j-series, 50.5 mAP yolov3-320) evolved by @ktian08 https://github.com/ultralytics/yolov3/issues/310 +# hyp = {'giou': 1.582, # giou loss gain # 'xy': 4.688, # xy loss gain # 'wh': 0.1857, # wh loss gain -# 'cls': 11.7, # cls loss gain -# 'cls_pw': 4.81, # cls BCELoss positive_weight -# 'obj': 11.5, # obj loss gain -# 'obj_pw': 1.56, # obj BCELoss positive_weight -# 'iou_t': 0.281, # iou training threshold -# 'lr0': 0.0013, # initial learning rate +# 'cls': 27.76, # cls loss gain (CE=~1.0, uCE=~20, uBCE=~200,~30) +# 'cls_pw': 1.446, # cls BCELoss positive_weight +# 'obj': 21.35, # obj loss gain +# 'obj_pw': 3.941, # obj BCELoss positive_weight +# 'iou_t': 0.2635, # iou training threshold +# 'lr0': 0.010324, # initial learning rate # 'lrf': -4., # final LambdaLR learning rate = lr0 * (10 ** lrf) -# 'momentum': 0.944, # SGD momentum -# 'weight_decay': 0.000427, # optimizer weight decay -# 'hsv_s': 0.0599, # image HSV-Saturation augmentation (fraction) -# 'hsv_v': 0.142, # image HSV-Value augmentation (fraction) -# 'degrees': 1.03, # image rotation (+/- deg) -# 'translate': 0.0552, # image translation (+/- fraction) -# 'scale': 0.0555, # image scale (+/- gain) -# 'shear': 0.434} # image shear (+/- deg) +# 'momentum': 0.97, # SGD momentum +# 'weight_decay': 0.0004569, # optimizer weight decay +# 'hsv_s': 0.5703, # image HSV-Saturation augmentation (fraction) +# 'hsv_v': 0.3174, # image HSV-Value augmentation (fraction) +# 'degrees': 1.113, # image rotation (+/- deg) +# 'translate': 0.06797, # image translation (+/- fraction) +# 'scale': 0.1059, # image scale (+/- gain) +# 'shear': 0.5768} # image shear (+/- deg) + +# Hyperparameters (i-series) +hyp = {'giou': 1.43, # giou loss gain + 'xy': 4.688, # xy loss gain + 'wh': 0.1857, # wh loss gain + 'cls': 11.7, # cls loss gain + 'cls_pw': 4.81, # cls BCELoss positive_weight + 'obj': 11.5, # obj loss gain + 'obj_pw': 1.56, # obj BCELoss positive_weight + 'iou_t': 0.281, # iou training threshold + 'lr0': 0.01, # initial learning rate + 'lrf': -4., # final LambdaLR learning rate = lr0 * (10 ** lrf) + 'momentum': 0.97, # SGD momentum + 'weight_decay': 0.000427, # optimizer weight decay + 'hsv_s': 0.0599, # image HSV-Saturation augmentation (fraction) + 'hsv_v': 0.142, # image HSV-Value augmentation (fraction) + 'degrees': 1.03, # image rotation (+/- deg) + 'translate': 0.0552, # image translation (+/- fraction) + 'scale': 0.0555, # image scale (+/- gain) + 'shear': 0.434} # image shear (+/- deg) def train(cfg, @@ -360,7 +360,7 @@ if __name__ == '__main__': parser.add_argument('--batch-size', type=int, default=32, help='batch size') parser.add_argument('--accumulate', type=int, default=2, help='number of batches to accumulate before optimizing') parser.add_argument('--cfg', type=str, default='cfg/yolov3-spp.cfg', help='cfg file path') - parser.add_argument('--data', type=str, default='data/coco.data', help='coco.data file path') + parser.add_argument('--data', type=str, default='data/coco_64img.data', help='coco.data file path') parser.add_argument('--multi-scale', action='store_true', help='train at (1/1.5)x - 1.5x sizes') parser.add_argument('--img-size', type=int, default=416, help='inference size (pixels)') parser.add_argument('--rect', action='store_true', help='rectangular training') diff --git a/utils/utils.py b/utils/utils.py index 0d2e2b39..e8fdbfa4 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -293,13 +293,14 @@ class FocalLoss(nn.Module): # i.e. criteria = FocalLoss(nn.BCEWithLogitsLoss(), gamma=2.5) def __init__(self, loss_fcn, alpha=1, gamma=2, reduction='mean'): super(FocalLoss, self).__init__() + loss_fcn.reduction = 'none' # required to apply FL to each element self.loss_fcn = loss_fcn self.alpha = alpha self.gamma = gamma self.reduction = reduction def forward(self, input, target): - loss = self.loss_fcn(input, target, reduction='none') + loss = self.loss_fcn(input, target) pt = torch.exp(-loss) loss *= self.alpha * (1 - pt) ** self.gamma