added OneCycleLR

This commit is contained in:
sugarme 2021-06-12 18:21:43 +10:00
parent 2fd99cdffd
commit 50dd5b181c
2 changed files with 3 additions and 3 deletions

View File

@ -1551,7 +1551,6 @@ func NewOneCycleLR(opt *Optimizer, maxLR float64, opts ...OneCycleOption) *OneCy
oc := new(OneCycleLR)
oc.opt = opt
oc.lastEpoch = options.LastEpoch
oc.totalSteps = options.TotalSteps
// validate pctStart
if options.PctStart < 0 || options.PctStart > 1 {
@ -1579,7 +1578,7 @@ func NewOneCycleLR(opt *Optimizer, maxLR float64, opts ...OneCycleOption) *OneCy
}
}
oc.stepSizeUp = int(options.PctStart*float64(options.TotalSteps)) - 1
oc.stepSizeUp = int(options.PctStart*float64(oc.totalSteps)) - 1
oc.stepSizeDown = oc.totalSteps - oc.stepSizeUp - 1
// validate annealStrategy

View File

@ -270,10 +270,11 @@ func TestOneCycleLR(t *testing.T) {
var lrs []float64
for i := 0; i < 100; i++ {
s.Step()
opt.Step()
lr := opt.GetLRs()[0]
lrs = append(lrs, lr)
t.Logf("batch %2d: lr %0.4f\n", i, lr)
s.Step()
}
// t.Logf("Lrs: %+v\n", lrs)
t.Log(model)