Commit 3dc87ab5 authored by Sean Bell's avatar Sean Bell Committed by Facebook Github Bot

Add cosine_delay learning rate policy

Summary:
This adds a cosine schedule, based on:
 - "Bag of Freebies for Training Object Detection Neural Networks" https://arxiv.org/pdf/1902.04103.pdf
  - "SGDR: Stochastic Gradient Descent with Warm Restarts" https://arxiv.org/pdf/1608.03983.pdf

Reviewed By: ashwinb

Differential Revision: D14593944

fbshipit-source-id: f0f7eedee784fa4d0aebd092d718526bbf627d81
parent b62314c6
...@@ -581,6 +581,8 @@ __C.SOLVER.LR_POLICY = 'step' ...@@ -581,6 +581,8 @@ __C.SOLVER.LR_POLICY = 'step'
# SOLVER.STEPS = [0, 60000, 80000] # SOLVER.STEPS = [0, 60000, 80000]
# SOLVER.LRS = [0.02, 0.002, 0.0002] # SOLVER.LRS = [0.02, 0.002, 0.0002]
# lr = LRS[current_step] # lr = LRS[current_step]
# 'cosine_decay'
# lr = SOLVER.BASE_LR * (cos(PI * cur_iter / SOLVER.MAX_ITER) * 0.5 + 0.5)
# Hyperparameter used by the specified policy # Hyperparameter used by the specified policy
# For 'step', the current LR is multiplied by SOLVER.GAMMA at each step # For 'step', the current LR is multiplied by SOLVER.GAMMA at each step
......
...@@ -91,6 +91,14 @@ def lr_func_step(cur_iter): ...@@ -91,6 +91,14 @@ def lr_func_step(cur_iter):
cfg.SOLVER.GAMMA ** (cur_iter // cfg.SOLVER.STEP_SIZE)) cfg.SOLVER.GAMMA ** (cur_iter // cfg.SOLVER.STEP_SIZE))
def lr_func_cosine_decay(cur_iter):
"""For cfg.SOLVER.LR_POLICY = 'cosine_decay'
"""
iter_frac = float(cur_iter) / cfg.SOLVER.MAX_ITER
cos_frac = 0.5 * (np.cos(np.pi * iter_frac) + 1)
return cfg.SOLVER.BASE_LR * cos_frac
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
# Helpers # Helpers
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment