From 94830854fab75faf99e8deeec2d2cf82e4e4a541 Mon Sep 17 00:00:00 2001 From: aweers <32593524+aweers@users.noreply.github.com> Date: Sun, 14 Apr 2019 19:44:33 +0200 Subject: [PATCH 1/6] [TF 2.0 docs] Add example for EarlyStopping I think a short example like this is very useful for user who don't have much experience and want to use a callback for their first time. --- tensorflow/python/keras/callbacks.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tensorflow/python/keras/callbacks.py b/tensorflow/python/keras/callbacks.py index 6374c8f9ed10e8..d5f1dcfe6a8744 100644 --- a/tensorflow/python/keras/callbacks.py +++ b/tensorflow/python/keras/callbacks.py @@ -1018,6 +1018,18 @@ class EarlyStopping(Callback): the epoch with the best value of the monitored quantity. If False, the model weights obtained at the last step of training are used. + + Example: + + ```python + # first create the callback + callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3) + # this callback will stop training when there is no improvement in + # validation loss for three epochs + # then simply train the model with the callback + model.fit(data, labels, epochs=100, callbacks=[callback], + validation_data=(val_data, val_labels)) + ``` """ def __init__(self, From c70b787103a8c6dd184793c27b51a787afa3291c Mon Sep 17 00:00:00 2001 From: Kilaru Yasaswi Sri Chandra Gandhi Date: Sun, 14 Apr 2019 22:04:41 +0200 Subject: [PATCH 2/6] Update tensorflow/python/keras/callbacks.py Co-Authored-By: aweers <32593524+aweers@users.noreply.github.com> --- tensorflow/python/keras/callbacks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/keras/callbacks.py b/tensorflow/python/keras/callbacks.py index d5f1dcfe6a8744..9cf3402fd1548f 100644 --- a/tensorflow/python/keras/callbacks.py +++ b/tensorflow/python/keras/callbacks.py @@ -1022,7 +1022,7 @@ class EarlyStopping(Callback): Example: ```python - # first create the callback + # Firstly, let's create the callback callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3) # this callback will stop training when there is no improvement in # validation loss for three epochs From 3db27fc813b9b818313549c6080a90720bfd3ea7 Mon Sep 17 00:00:00 2001 From: Kilaru Yasaswi Sri Chandra Gandhi Date: Sun, 14 Apr 2019 22:04:55 +0200 Subject: [PATCH 3/6] Update tensorflow/python/keras/callbacks.py Co-Authored-By: aweers <32593524+aweers@users.noreply.github.com> --- tensorflow/python/keras/callbacks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/keras/callbacks.py b/tensorflow/python/keras/callbacks.py index 9cf3402fd1548f..4755007d19a040 100644 --- a/tensorflow/python/keras/callbacks.py +++ b/tensorflow/python/keras/callbacks.py @@ -1024,7 +1024,7 @@ class EarlyStopping(Callback): ```python # Firstly, let's create the callback callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3) - # this callback will stop training when there is no improvement in + # This callback will stop training when there is no improvement in # validation loss for three epochs # then simply train the model with the callback model.fit(data, labels, epochs=100, callbacks=[callback], From 4d4794806b565656e3c6a5844be159e84867cd4c Mon Sep 17 00:00:00 2001 From: Kilaru Yasaswi Sri Chandra Gandhi Date: Sun, 14 Apr 2019 22:05:10 +0200 Subject: [PATCH 4/6] Update tensorflow/python/keras/callbacks.py Co-Authored-By: aweers <32593524+aweers@users.noreply.github.com> --- tensorflow/python/keras/callbacks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/keras/callbacks.py b/tensorflow/python/keras/callbacks.py index 4755007d19a040..5de9f893574968 100644 --- a/tensorflow/python/keras/callbacks.py +++ b/tensorflow/python/keras/callbacks.py @@ -1025,7 +1025,7 @@ class EarlyStopping(Callback): # Firstly, let's create the callback callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3) # This callback will stop training when there is no improvement in - # validation loss for three epochs + # the validation loss for three consecutive epochs. # then simply train the model with the callback model.fit(data, labels, epochs=100, callbacks=[callback], validation_data=(val_data, val_labels)) From 33bf0e328ee97eb66cf54d539a5aad7735a8245c Mon Sep 17 00:00:00 2001 From: Kilaru Yasaswi Sri Chandra Gandhi Date: Sun, 14 Apr 2019 22:05:21 +0200 Subject: [PATCH 5/6] Update tensorflow/python/keras/callbacks.py Co-Authored-By: aweers <32593524+aweers@users.noreply.github.com> --- tensorflow/python/keras/callbacks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/keras/callbacks.py b/tensorflow/python/keras/callbacks.py index 5de9f893574968..9135df16c111b3 100644 --- a/tensorflow/python/keras/callbacks.py +++ b/tensorflow/python/keras/callbacks.py @@ -1026,7 +1026,7 @@ class EarlyStopping(Callback): callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3) # This callback will stop training when there is no improvement in # the validation loss for three consecutive epochs. - # then simply train the model with the callback + # We now simply train the model with the callback. model.fit(data, labels, epochs=100, callbacks=[callback], validation_data=(val_data, val_labels)) ``` From 096d4f52181e0b7d4c338dc209832af33a8a29d1 Mon Sep 17 00:00:00 2001 From: aweers <32593524+aweers@users.noreply.github.com> Date: Mon, 22 Apr 2019 20:25:07 +0200 Subject: [PATCH 6/6] Remove self-explanatory comments --- tensorflow/python/keras/callbacks.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tensorflow/python/keras/callbacks.py b/tensorflow/python/keras/callbacks.py index 9135df16c111b3..a59612b44ade59 100644 --- a/tensorflow/python/keras/callbacks.py +++ b/tensorflow/python/keras/callbacks.py @@ -1022,11 +1022,9 @@ class EarlyStopping(Callback): Example: ```python - # Firstly, let's create the callback callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3) - # This callback will stop training when there is no improvement in + # This callback will stop the training when there is no improvement in # the validation loss for three consecutive epochs. - # We now simply train the model with the callback. model.fit(data, labels, epochs=100, callbacks=[callback], validation_data=(val_data, val_labels)) ```