Do not reuse optimizer from previous model

main
Aurélien Geron 2024-01-10 19:15:03 +13:00
parent 856d7de430
commit 1f8c9df846
1 changed files with 10 additions and 2 deletions

View File

@ -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": {