134
134
type = str ,
135
135
help = "Padding char for plates with length less than '--plate-slots'." ,
136
136
)
137
+ @click .option (
138
+ "--early-stopping-patience" ,
139
+ default = 120 ,
140
+ show_default = True ,
141
+ type = int ,
142
+ help = "Stop training when 'val_plate_acc' doesn't improve for X epochs." ,
143
+ )
144
+ @click .option (
145
+ "--reduce-lr-patience" ,
146
+ default = 100 ,
147
+ show_default = True ,
148
+ type = int ,
149
+ help = "Reduce the learning rate by 0.5x if 'val_plate_acc' doesn't improve within X epochs." ,
150
+ )
137
151
def train (
138
152
model_type : str ,
139
153
dense : bool ,
@@ -151,6 +165,8 @@ def train(
151
165
alphabet : str ,
152
166
vocab_size : int ,
153
167
pad_char : str ,
168
+ early_stopping_patience : int ,
169
+ reduce_lr_patience : int ,
154
170
) -> None :
155
171
train_torch_dataset = LicensePlateDataset (
156
172
annotations_file = annotations ,
@@ -201,9 +217,20 @@ def train(
201
217
202
218
callbacks = [
203
219
# Reduce the learning rate by 0.5x if 'val_plate_acc' doesn't improve within X epochs
204
- ReduceLROnPlateau ("val_plate_acc" , verbose = 1 , patience = 35 , factor = 0.5 , min_lr = 1e-5 ),
220
+ ReduceLROnPlateau (
221
+ "val_plate_acc" ,
222
+ verbose = 1 ,
223
+ patience = reduce_lr_patience ,
224
+ factor = 0.5 ,
225
+ min_lr = 1e-5 ,
226
+ ),
205
227
# Stop training when 'val_plate_acc' doesn't improve for X epochs
206
- EarlyStopping (monitor = "val_plate_acc" , patience = 50 , mode = "max" , restore_best_weights = True ),
228
+ EarlyStopping (
229
+ monitor = "val_plate_acc" ,
230
+ patience = early_stopping_patience ,
231
+ mode = "max" ,
232
+ restore_best_weights = True ,
233
+ ),
207
234
]
208
235
209
236
if tensorboard :
0 commit comments