From 4186ba4441fc3abcc8835a4a526812090458a517 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 6 Feb 2021 11:25:49 -0800 Subject: [PATCH 1/2] Linear LR scheduler option --- train.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/train.py b/train.py index ba48896f1e94..6ab2a8d07f2d 100644 --- a/train.py +++ b/train.py @@ -120,7 +120,10 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # Scheduler https://arxiv.org/pdf/1812.01187.pdf # https://pytorch.org/docs/stable/_modules/torch/optim/lr_scheduler.html#OneCycleLR - lf = one_cycle(1, hyp['lrf'], epochs) # cosine 1->hyp['lrf'] + if opt.linear_lr: + lf = lambda x: (1 - x / (epochs - 1)) * (1.0 - hyp['lrf']) + hyp['lrf'] # linear + else: + lf = one_cycle(1, hyp['lrf'], epochs) # cosine 1->hyp['lrf'] scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf) # plot_lr_scheduler(optimizer, scheduler, epochs) @@ -464,6 +467,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser.add_argument('--name', default='exp', help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') parser.add_argument('--quad', action='store_true', help='quad dataloader') + parser.add_argument('--linear-lr', action='store_true', help='linear LR') opt = parser.parse_args() # Set DDP variables From c4aa85c90666bf565f776391f5392c1f35e19be4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 6 Feb 2021 11:26:22 -0800 Subject: [PATCH 2/2] Update train.py --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index 6ab2a8d07f2d..4065e1f149ef 100644 --- a/train.py +++ b/train.py @@ -467,7 +467,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): parser.add_argument('--name', default='exp', help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') parser.add_argument('--quad', action='store_true', help='quad dataloader') - parser.add_argument('--linear-lr', action='store_true', help='linear LR') + parser.add_argument('--linear-lr', action='store_true', help='linear LR') opt = parser.parse_args() # Set DDP variables