Is it possible to apply Early Stopping after specified number of epochs in Keras. For example I want to train my NN for 45 epoch, and then start using EarlyStopping.
So far I did it like this:
early_stop = EarlyStopping(monitor='val_loss', mode='min', verbose=1, baseline = 0.1, patience = 3)
opt = Adam(lr = .00001, beta_1=0.9, beta_2=0.999, epsilon=1e-8)
model.compile(optimizer=opt, loss='categorical_crossentropy', metrics = ['accuracy'])
mod = model.fit_generator(train_batches, steps_per_epoch = 66, validation_data = valid_batches, validation_steps = 22, epochs = 45, verbose = 1)
mod = model.fit_generator(train_batches, steps_per_epoch = 66, validation_data = valid_batches, validation_steps = 22, epochs = 50, callbacks = [early_stop], verbose = 1)
But doing it this way, produces only a few step graph for training
Is there a way I can write this all together? Any help much appreciated!
I think we can use a custom callback from Keras library to do this. Define your custom callback as follows: