SGD now defaults to lr=0.01 so use 1e-3 explicitely

main
Aurélien Geron 2019-06-10 10:48:00 +08:00
parent 1973371b19
commit 3db31444cd
1 changed files with 21 additions and 11 deletions

View File

@ -511,7 +511,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"model.compile(loss=\"sparse_categorical_crossentropy\", optimizer=\"sgd\",\n", "model.compile(loss=\"sparse_categorical_crossentropy\",\n",
" optimizer=keras.optimizers.SGD(lr=1e-3),\n",
" metrics=[\"accuracy\"])" " metrics=[\"accuracy\"])"
] ]
}, },
@ -582,7 +583,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"model.compile(loss=\"sparse_categorical_crossentropy\", optimizer=\"sgd\",\n", "model.compile(loss=\"sparse_categorical_crossentropy\",\n",
" optimizer=keras.optimizers.SGD(lr=1e-3),\n",
" metrics=[\"accuracy\"])" " metrics=[\"accuracy\"])"
] ]
}, },
@ -661,7 +663,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"model.compile(loss=\"sparse_categorical_crossentropy\", optimizer=\"sgd\",\n", "model.compile(loss=\"sparse_categorical_crossentropy\",\n",
" optimizer=keras.optimizers.SGD(lr=1e-3),\n",
" metrics=[\"accuracy\"])" " metrics=[\"accuracy\"])"
] ]
}, },
@ -707,7 +710,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"model.compile(loss=\"sparse_categorical_crossentropy\", optimizer=\"sgd\",\n", "model.compile(loss=\"sparse_categorical_crossentropy\",\n",
" optimizer=keras.optimizers.SGD(lr=1e-3),\n",
" metrics=[\"accuracy\"])" " metrics=[\"accuracy\"])"
] ]
}, },
@ -866,7 +870,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"model_A.compile(loss=\"sparse_categorical_crossentropy\", optimizer=\"sgd\",\n", "model_A.compile(loss=\"sparse_categorical_crossentropy\",\n",
" optimizer=keras.optimizers.SGD(lr=1e-3),\n",
" metrics=[\"accuracy\"])" " metrics=[\"accuracy\"])"
] ]
}, },
@ -908,7 +913,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"model_B.compile(loss=\"binary_crossentropy\", optimizer=\"sgd\",\n", "model_B.compile(loss=\"binary_crossentropy\",\n",
" optimizer=keras.optimizers.SGD(lr=1e-3),\n",
" metrics=[\"accuracy\"])" " metrics=[\"accuracy\"])"
] ]
}, },
@ -961,7 +967,8 @@
"for layer in model_B_on_A.layers[:-1]:\n", "for layer in model_B_on_A.layers[:-1]:\n",
" layer.trainable = False\n", " layer.trainable = False\n",
"\n", "\n",
"model_B_on_A.compile(loss=\"binary_crossentropy\", optimizer=\"sgd\",\n", "model_B_on_A.compile(loss=\"binary_crossentropy\",\n",
" optimizer=keras.optimizers.SGD(lr=1e-3),\n",
" metrics=[\"accuracy\"])" " metrics=[\"accuracy\"])"
] ]
}, },
@ -977,7 +984,8 @@
"for layer in model_B_on_A.layers[:-1]:\n", "for layer in model_B_on_A.layers[:-1]:\n",
" layer.trainable = True\n", " layer.trainable = True\n",
"\n", "\n",
"model_B_on_A.compile(loss=\"binary_crossentropy\", optimizer=\"sgd\",\n", "model_B_on_A.compile(loss=\"binary_crossentropy\",\n",
" optimizer=keras.optimizers.SGD(lr=1e-3),\n",
" metrics=[\"accuracy\"])\n", " metrics=[\"accuracy\"])\n",
"history = model_B_on_A.fit(X_train_B, y_train_B, epochs=16,\n", "history = model_B_on_A.fit(X_train_B, y_train_B, epochs=16,\n",
" validation_data=(X_valid_B, y_valid_B))" " validation_data=(X_valid_B, y_valid_B))"
@ -1638,7 +1646,9 @@
" keras.layers.Dense(100, activation=\"selu\", kernel_initializer=\"lecun_normal\"),\n", " keras.layers.Dense(100, activation=\"selu\", kernel_initializer=\"lecun_normal\"),\n",
" keras.layers.Dense(10, activation=\"softmax\")\n", " keras.layers.Dense(10, activation=\"softmax\")\n",
"])\n", "])\n",
"model.compile(loss=\"sparse_categorical_crossentropy\", optimizer=\"sgd\", metrics=[\"accuracy\"])" "model.compile(loss=\"sparse_categorical_crossentropy\",\n",
" optimizer=keras.optimizers.SGD(lr=1e-3),\n",
" metrics=[\"accuracy\"])"
] ]
}, },
{ {