lmoroney / dlaicourse

Notebooks for learning deep learning
5.66k stars 5.36k forks source link

Exercise2-Answer.ipynb: it should get acc instead of accuracy #96

Open yohei1126 opened 4 years ago

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

This does not work. logs.get('accuracy') always returns None. It should be

class myCallback(tf.keras.callbacks.Callback):
  def on_epoch_end(self, epoch, logs={}):
    if(logs.get('acc')>0.6):
      print("\nReached 60% accuracy so cancelling training!")
      self.model.stop_training = True
p14jeffwest commented 4 years ago

Yes, I had a sames result. logs.get('accuracy') made error but logs.get('acc') is ok.

geetanjaligg commented 4 years ago

This is because of Tensorflow 1. If you upgrade it to Tensorflow 2, 'accuracy' should work.