How can I implement an early stopping criteria - Tensorflow Object Detection API

1.3k Views Asked by At

Fairly new to the Object Detection API here, using tf-gpu==1.15 for training and 2.2.0 for evaluation as well as python 3.7.

I am able to utilize data augmentation as well as adjust the decay of the learning rate in the ssd_mobilenet_v1.config file, but I am not sure how to go about implementing a way for the model to stop training if I am confident the loss will not get below a certain value no matter how many more steps it trains.

How or where do I configure / implement early stopping criteria?

1

There are 1 best solutions below

5
On

You can make use of EarlyStopping callback from tensorflow. Refer tensorflow documentation here.

Create a callback using -

from tensorflow.keras.callbacks import EarlyStopping

es = EarlyStopping(
    monitor='val_loss', min_delta=0, patience=3, verbose=0, mode='auto',
    baseline=None, restore_best_weights=False
)
  • monitor - Change the monitor param to loss if u don't have validation data & want to stop training if training loss stops decreasing for 3 consecutive epochs. Also, u can change it to accuracy if u wish to stop training based on accuracy instead of loss.
  • patience - Number of epochs to wait before stopping the training if loss doesn't decrease or accuracy doesn't improve

Then pass it to fit function while training -

history = model.fit(X, y, epochs=10, callbacks=[es])

There are many examples online, u can check them!