glenn-jocher commited on
Commit
a936f5f
·
unverified ·
1 Parent(s): dbbb57c

Switch default LR scheduler from cos to linear (#6729)

Browse files

* Switch default LR scheduler from cos to linear

Based on empirical results of training both ways on all YOLOv5 models.

* linear bug fix

Files changed (1) hide show
  1. train.py +4 -4
train.py CHANGED
@@ -176,10 +176,10 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
176
  del g0, g1, g2
177
 
178
  # Scheduler
179
- if opt.linear_lr:
180
- lf = lambda x: (1 - x / (epochs - 1)) * (1.0 - hyp['lrf']) + hyp['lrf'] # linear
181
- else:
182
  lf = one_cycle(1, hyp['lrf'], epochs) # cosine 1->hyp['lrf']
 
 
183
  scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf) # plot_lr_scheduler(optimizer, scheduler, epochs)
184
 
185
  # EMA
@@ -479,7 +479,7 @@ def parse_opt(known=False):
479
  parser.add_argument('--name', default='exp', help='save to project/name')
480
  parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
481
  parser.add_argument('--quad', action='store_true', help='quad dataloader')
482
- parser.add_argument('--linear-lr', action='store_true', help='linear LR')
483
  parser.add_argument('--label-smoothing', type=float, default=0.0, help='Label smoothing epsilon')
484
  parser.add_argument('--patience', type=int, default=100, help='EarlyStopping patience (epochs without improvement)')
485
  parser.add_argument('--freeze', nargs='+', type=int, default=[0], help='Freeze layers: backbone=10, first3=0 1 2')
 
176
  del g0, g1, g2
177
 
178
  # Scheduler
179
+ if opt.cos_lr:
 
 
180
  lf = one_cycle(1, hyp['lrf'], epochs) # cosine 1->hyp['lrf']
181
+ else:
182
+ lf = lambda x: (1 - x / epochs) * (1.0 - hyp['lrf']) + hyp['lrf'] # linear
183
  scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf) # plot_lr_scheduler(optimizer, scheduler, epochs)
184
 
185
  # EMA
 
479
  parser.add_argument('--name', default='exp', help='save to project/name')
480
  parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
481
  parser.add_argument('--quad', action='store_true', help='quad dataloader')
482
+ parser.add_argument('--cos-lr', action='store_true', help='cosine LR scheduler')
483
  parser.add_argument('--label-smoothing', type=float, default=0.0, help='Label smoothing epsilon')
484
  parser.add_argument('--patience', type=int, default=100, help='EarlyStopping patience (epochs without improvement)')
485
  parser.add_argument('--freeze', nargs='+', type=int, default=[0], help='Freeze layers: backbone=10, first3=0 1 2')