callbacks to trigger stop_training

Related tutorials:

Use callbacks to trigger the end of training cycles

Code:

class myCallback(tf.keras.callbacks.Callback):
  def on_epoch_end(self, epoch, logs={}):
    if(logs.get('accuracy')>0.9):
      print("\nReached 90% accuracy so cancelling training!")
      self.model.stop_training = True

Imports:

callbacks = myCallback()

#example usage:
model.fit(value_a, value_b, epochs=500, callbacks=[callbacks])

Blog at WordPress.com.