added OneCycleLR
This commit is contained in:
parent
2fd99cdffd
commit
50dd5b181c
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user