From dbc999f857d459edc60d7e7aeb19154efc415d42 Mon Sep 17 00:00:00 2001 From: gdarkwah <61522557+gdarkwah@users.noreply.github.com> Date: Wed, 2 Mar 2022 13:15:56 -0600 Subject: [PATCH 1/2] update to checkpoint callback options (save_frequency) introduced the number of batches ('n_batches') option for the save frequency instead of 'batch_size'. Using 'batch_size' works in this tutorial because the length of the training data is 1000 which coincidentally results in a rounded value of ~32 when it is divided by the 'batch_size'. In cases when the number of samples is not 1000, this will result in the model saving at different epoch frequencies other than after every 5 epochs. the definition of 'save_freq' (https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/ModelCheckpoint#args) clearly refers to the number of batches ('n_batches' in this context) and not the number of samples in a batch ('batch_size'). --- site/en/tutorials/keras/save_and_load.ipynb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/site/en/tutorials/keras/save_and_load.ipynb b/site/en/tutorials/keras/save_and_load.ipynb index 6e48a08a4a6..a75e01116ba 100644 --- a/site/en/tutorials/keras/save_and_load.ipynb +++ b/site/en/tutorials/keras/save_and_load.ipynb @@ -385,12 +385,17 @@ "\n", "batch_size = 32\n", "\n", + "# calculate the number of batches per epoch\n", + "import math\n", + "n_batches = len(train_images) / batch_size\n", + "n_batches = math.ceil(n_batches) # round up the number of batches to the nearest whole integer\n", + "\n", "# Create a callback that saves the model's weights every 5 epochs\n", "cp_callback = tf.keras.callbacks.ModelCheckpoint(\n", " filepath=checkpoint_path, \n", " verbose=1, \n", " save_weights_only=True,\n", - " save_freq=5*batch_size)\n", + " save_freq=5*n_batches)\n", "\n", "# Create a new model instance\n", "model = create_model()\n", From 2f7592f779f9f08631ffa2ab13305ae2519ee5eb Mon Sep 17 00:00:00 2001 From: 8bitmp3 <19637339+8bitmp3@users.noreply.github.com> Date: Mon, 3 Apr 2023 21:37:39 +0000 Subject: [PATCH 2/2] Update site/en/tutorials/keras/save_and_load.ipynb --- site/en/tutorials/keras/save_and_load.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/en/tutorials/keras/save_and_load.ipynb b/site/en/tutorials/keras/save_and_load.ipynb index a75e01116ba..7621bea1aaa 100644 --- a/site/en/tutorials/keras/save_and_load.ipynb +++ b/site/en/tutorials/keras/save_and_load.ipynb @@ -385,7 +385,7 @@ "\n", "batch_size = 32\n", "\n", - "# calculate the number of batches per epoch\n", + "# Calculate the number of batches per epoch\n", "import math\n", "n_batches = len(train_images) / batch_size\n", "n_batches = math.ceil(n_batches) # round up the number of batches to the nearest whole integer\n",