Linear LR scheduler option (#2150)
Browse files* Linear LR scheduler option
* Update train.py
train.py
CHANGED
@@ -120,7 +120,10 @@ def train(hyp, opt, device, tb_writer=None, wandb=None):
|
|
120 |
|
121 |
# Scheduler https://arxiv.org/pdf/1812.01187.pdf
|
122 |
# https://pytorch.org/docs/stable/_modules/torch/optim/lr_scheduler.html#OneCycleLR
|
123 |
-
|
|
|
|
|
|
|
124 |
scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf)
|
125 |
# plot_lr_scheduler(optimizer, scheduler, epochs)
|
126 |
|
@@ -464,6 +467,7 @@ if __name__ == '__main__':
|
|
464 |
parser.add_argument('--name', default='exp', help='save to project/name')
|
465 |
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
|
466 |
parser.add_argument('--quad', action='store_true', help='quad dataloader')
|
|
|
467 |
opt = parser.parse_args()
|
468 |
|
469 |
# Set DDP variables
|
|
|
120 |
|
121 |
# Scheduler https://arxiv.org/pdf/1812.01187.pdf
|
122 |
# https://pytorch.org/docs/stable/_modules/torch/optim/lr_scheduler.html#OneCycleLR
|
123 |
+
if opt.linear_lr:
|
124 |
+
lf = lambda x: (1 - x / (epochs - 1)) * (1.0 - hyp['lrf']) + hyp['lrf'] # linear
|
125 |
+
else:
|
126 |
+
lf = one_cycle(1, hyp['lrf'], epochs) # cosine 1->hyp['lrf']
|
127 |
scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf)
|
128 |
# plot_lr_scheduler(optimizer, scheduler, epochs)
|
129 |
|
|
|
467 |
parser.add_argument('--name', default='exp', help='save to project/name')
|
468 |
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
|
469 |
parser.add_argument('--quad', action='store_true', help='quad dataloader')
|
470 |
+
parser.add_argument('--linear-lr', action='store_true', help='linear LR')
|
471 |
opt = parser.parse_args()
|
472 |
|
473 |
# Set DDP variables
|