Code for W4 Time Series Notebook on using a callback to stop training after a certain mae model: LSTM
class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs={}):
'''
Halts the training when a certain metric is met
Args:
epoch (integer) - index of epoch (required but unused in the function definition below)
logs (dict) - metric results from the training epoch
'''
# Check the validation set MAE
if(logs.get('val_mae') < 5.2):
# Stop if threshold is met
print("\nRequired val MAE is met so cancelling training!")
self.model.stop_training = True
# Instantiate the class
callbacks = myCallback()
returns the error 'TypeError: '<' not supported between instances of 'NoneType' and 'float' on line ' if(logs.get('val_mae') < 5.2):'
Any help on the above will be appreciated!
Hi! Did you manage to solve this? If not, consider joining our community where mentors can assist you with these kinds of issues.
Sorry for the late response