i didn’t get where is the problem, plz give me some clues.
here is my code:
Hello @Chris_Leng
Welcome to our Community! Thanks for reaching out. We are here to help you.
You did an excellent job with your results; However, I just found two small mistakes than can affect the results.
The first one is to change the word epochs to epoch; remember that Python is word sensible when defining the variables.
And the other mistake that maybe affect the result can be the word accuracy. Tensorflow changed the dictionary tag ‘accuracy’ to ‘acc’; if you can try altered like that, it will be great.
class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs={}):
if logs.get('acc') is not None and logs.get('acc') > 0.99:
print("\nReached 99% accuracy so cancelling training!")
self.model.stop_training = True
I recommend first changing just the word epoch; if it doesn’t work, try the other one. If it does not work, please send me your full Jupyter or google collab; maybe the problem is not in that specific part; perhaps the error is when you init the callback.
Change it a let me know if that works.
Hopefully, help
Remember to inherit from the correct class
class myCallback(tf.keras.callbacks.Callback):
# Define the correct function signature for on_epoch_end
def on_epoch_end(self, epoch, logs={}):
if logs.get(‘accuracy’) is not None and logs.get(‘accuracy’) >= 0.99:
print(“\nReached 99% accuracy so cancelling training!”)
# Stop training once the above condition is met
self.model.stop_training = True