From 1f8c9df846cf90b6aa3845bbc07b667766c415d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Wed, 10 Jan 2024 19:15:03 +1300 Subject: [PATCH] Do not reuse optimizer from previous model --- 14_deep_computer_vision_with_cnns.ipynb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/14_deep_computer_vision_with_cnns.ipynb b/14_deep_computer_vision_with_cnns.ipynb index 074c451..cd2bdaf 100644 --- a/14_deep_computer_vision_with_cnns.ipynb +++ b/14_deep_computer_vision_with_cnns.ipynb @@ -1848,6 +1848,13 @@ "# Classification and Localization" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Note**: the code below used to reuse the optimizer from the previous model. This was fine in earlier versions of TensorFlow, but in more recent versions it can cause some issues, so I added a line to create a new optimizer here." + ] + }, { "cell_type": "code", "execution_count": 55, @@ -1864,6 +1871,7 @@ "loc_output = tf.keras.layers.Dense(4)(avg)\n", "model = tf.keras.Model(inputs=base_model.input,\n", " outputs=[class_output, loc_output])\n", + "optimizer = tf.keras.optimizers.SGD(learning_rate=0.01, momentum=0.9) # added this line\n", "model.compile(loss=[\"sparse_categorical_crossentropy\", \"mse\"],\n", " loss_weights=[0.8, 0.2], # depends on what you care most about\n", " optimizer=optimizer, metrics=[\"accuracy\"])" @@ -2207,7 +2215,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -2221,7 +2229,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.6" + "version": "3.10.13" }, "nav_menu": {}, "toc": {