mirror of
https://github.com/ArthurDanjou/handson-ml3.git
synced 2026-01-14 12:14:36 +01:00
Do not reuse optimizer from previous model
This commit is contained in:
@@ -1848,6 +1848,13 @@
|
|||||||
"# Classification and Localization"
|
"# 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",
|
"cell_type": "code",
|
||||||
"execution_count": 55,
|
"execution_count": 55,
|
||||||
@@ -1864,6 +1871,7 @@
|
|||||||
"loc_output = tf.keras.layers.Dense(4)(avg)\n",
|
"loc_output = tf.keras.layers.Dense(4)(avg)\n",
|
||||||
"model = tf.keras.Model(inputs=base_model.input,\n",
|
"model = tf.keras.Model(inputs=base_model.input,\n",
|
||||||
" outputs=[class_output, loc_output])\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",
|
"model.compile(loss=[\"sparse_categorical_crossentropy\", \"mse\"],\n",
|
||||||
" loss_weights=[0.8, 0.2], # depends on what you care most about\n",
|
" loss_weights=[0.8, 0.2], # depends on what you care most about\n",
|
||||||
" optimizer=optimizer, metrics=[\"accuracy\"])"
|
" optimizer=optimizer, metrics=[\"accuracy\"])"
|
||||||
@@ -2207,7 +2215,7 @@
|
|||||||
"provenance": []
|
"provenance": []
|
||||||
},
|
},
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python 3",
|
"display_name": "Python 3 (ipykernel)",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "python3"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
@@ -2221,7 +2229,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.10.6"
|
"version": "3.10.13"
|
||||||
},
|
},
|
||||||
"nav_menu": {},
|
"nav_menu": {},
|
||||||
"toc": {
|
"toc": {
|
||||||
|
|||||||
Reference in New Issue
Block a user