@@ -31,7 +31,6 @@ def __init__(self,
31
31
iterations ,
32
32
lr ,
33
33
policy ,
34
- min_lr = 0.0 ,
35
34
warm_up = 0.1 ,
36
35
min_momentum = 0.85 ,
37
36
max_momentum = 0.95 ,
@@ -40,15 +39,13 @@ def __init__(self,
40
39
decay_step = 0.1 ,
41
40
double_step = True ):
42
41
assert 0.0 <= lr <= 1.0
43
- assert 0.0 <= min_lr <= 1.0
44
42
assert 0.0 <= warm_up <= 1.0
45
43
assert 0.0 <= min_momentum <= 1.0
46
44
assert 0.0 <= max_momentum <= 1.0
47
45
assert 0.0 <= decay_step <= 1.0
48
46
assert policy in ['constant' , 'step' , 'cosine' , 'onecycle' ]
49
47
self .lr = lr
50
48
self .policy = policy
51
- self .min_lr = min_lr
52
49
self .max_lr = self .lr
53
50
self .warm_up = warm_up
54
51
self .min_momentum = min_momentum
@@ -57,6 +54,7 @@ def __init__(self,
57
54
self .cycle_length = initial_cycle_length
58
55
self .cycle_weight = cycle_weight
59
56
self .decay_step = decay_step
57
+ self .min_lr = self .lr * self .decay_step ** 2.0
60
58
self .double_step = double_step
61
59
self .cycle_step = 0
62
60
@@ -92,7 +90,7 @@ def __schedule_step_decay(self, optimizer, iteration_count):
92
90
if warm_up_iteration > 0 and iteration_count <= warm_up_iteration :
93
91
lr = self .__warm_up_lr (iteration_count , warm_up_iteration )
94
92
elif self .double_step and iteration_count >= int (self .iterations * 0.9 ):
95
- lr = self .lr * self .decay_step * self . decay_step
93
+ lr = self .lr * self .decay_step ** 2.0
96
94
elif iteration_count >= int (self .iterations * 0.8 ):
97
95
lr = self .lr * self .decay_step
98
96
else :
@@ -101,19 +99,19 @@ def __schedule_step_decay(self, optimizer, iteration_count):
101
99
return lr
102
100
103
101
def __schedule_one_cycle (self , optimizer , iteration_count ):
104
- warm_up = 0.3
105
- min_lr = self .min_lr
102
+ min_lr = 0.0
106
103
max_lr = self .max_lr
107
104
min_mm = self .min_momentum
108
105
max_mm = self .max_momentum
109
- warm_up_iterations = int (self .iterations * warm_up )
110
- if iteration_count <= warm_up_iterations :
106
+ warm_up_iterations = int (self .iterations * self . warm_up )
107
+ if warm_up_iterations > 0 and iteration_count <= warm_up_iterations :
111
108
iterations = warm_up_iterations
112
109
lr = ((np .cos (((iteration_count * np .pi ) / iterations ) + np .pi ) + 1.0 ) * 0.5 ) * (max_lr - min_lr ) + min_lr # increase only until target iterations
113
110
mm = ((np .cos (((iteration_count * np .pi ) / iterations ) + 0.0 ) + 1.0 ) * 0.5 ) * (max_mm - min_mm ) + min_mm # decrease only until target iterations
114
111
self .__set_lr (optimizer , lr )
115
112
self .__set_momentum (optimizer , mm )
116
113
else :
114
+ min_lr = self .min_lr
117
115
iteration_count -= warm_up_iterations + 1
118
116
iterations = self .iterations - warm_up_iterations
119
117
lr = ((np .cos (((iteration_count * np .pi ) / iterations ) + 0.0 ) + 1.0 ) * 0.5 ) * (max_lr - min_lr ) + min_lr # decrease only until target iterations
@@ -140,7 +138,7 @@ def plot_lr(policy):
140
138
import tensorflow as tf
141
139
from matplotlib import pyplot as plt
142
140
lr = 0.001
143
- warm_up = 0.1
141
+ warm_up = 0.3
144
142
decay_step = 0.2
145
143
iterations = 37500
146
144
iterations = int (iterations / (1.0 - warm_up ))
0 commit comments