Skip to content

Commit

Permalink
Keras guides snapshot: Fri, 27 Aug 2021 07:01:51 GMT
Browse files Browse the repository at this point in the history
  • Loading branch information
tfdocsbot committed Aug 27, 2021
1 parent 91fcc12 commit 5677c3d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
55 changes: 32 additions & 23 deletions site/en/guide/keras/training_keras_models_on_cloud.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,30 @@
{
"cell_type": "markdown",
"metadata": {
"id": "3768731d025f"
"id": "9bd759167bec"
},
"source": [
"## Import required modules\n",
"\n",
"This guide requires TensorFlow Cloud, which you can install via:\n",
"\n",
"`pip install tensorflow-cloud`"
"This guide requires TensorFlow Cloud, which you can install via:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "99e5bc5e0ab8"
},
"outputs": [],
"source": [
"!pip install -q tensorflow_cloud"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2dee4b3b0f30"
"id": "a12c7aae20fd"
},
"outputs": [],
"source": [
Expand All @@ -126,7 +135,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "e264e24fd8f1"
"id": "60d7f98d688b"
},
"source": [
"## Project Configurations\n",
Expand All @@ -144,7 +153,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "31dbaa3f9b16"
"id": "d7934fe353a0"
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -172,7 +181,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "eed0e648608a"
"id": "928bf01b789c"
},
"source": [
"## Authenticating the notebook to use your Google Cloud Project\n",
Expand All @@ -190,7 +199,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f0a9300ba7bd"
"id": "e71f08585210"
},
"outputs": [],
"source": [
Expand All @@ -214,7 +223,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "689ecfc05952"
"id": "951ab98602d1"
},
"source": [
"## Model and data setup\n",
Expand All @@ -231,7 +240,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "c8dbb31a610b"
"id": "574d8ef553e4"
},
"outputs": [],
"source": [
Expand All @@ -244,7 +253,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "6fe4bce33f09"
"id": "0a0e8155fb29"
},
"source": [
"### Create a model and prepare for training\n",
Expand All @@ -256,7 +265,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "67b17e1debc5"
"id": "949923c3ebce"
},
"outputs": [],
"source": [
Expand All @@ -280,7 +289,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "694ea19488d1"
"id": "4bde02ee81f6"
},
"source": [
"### Quick validation training\n",
Expand All @@ -295,7 +304,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "9babd8771221"
"id": "0f4f06e09b7d"
},
"outputs": [],
"source": [
Expand All @@ -307,7 +316,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "ae5e255dc88a"
"id": "5af44067f626"
},
"source": [
"## Prepare for remote training\n",
Expand All @@ -331,7 +340,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "99c73ab7b7ae"
"id": "5a1b793a653e"
},
"outputs": [],
"source": [
Expand All @@ -353,7 +362,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "cb8505bf596d"
"id": "581b48126087"
},
"source": [
"## Start the remote training\n",
Expand Down Expand Up @@ -400,7 +409,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "14e001767c59"
"id": "80d90d99f29a"
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -429,7 +438,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "b1efeedcc31d"
"id": "2dfae5812a97"
},
"source": [
"## Training Results\n",
Expand Down Expand Up @@ -459,7 +468,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "e8bb043598b8"
"id": "6926f225067a"
},
"outputs": [],
"source": [
Expand All @@ -471,7 +480,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "607aee95d918"
"id": "95779da080f5"
},
"source": [
"## Load your trained model\n",
Expand All @@ -484,7 +493,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "74c9146358b0"
"id": "c2115977acf2"
},
"outputs": [],
"source": [
Expand Down
20 changes: 8 additions & 12 deletions site/en/guide/keras/transfer_learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "bc999e4672c3"
"id": "6743c69b0952"
},
"source": [
"## Build a model\n",
Expand All @@ -770,7 +770,7 @@
"\n",
"Note that:\n",
"\n",
"- We add a `Normalization` layer to scale input values (initially in the `[0, 255]`\n",
"- We add a `Rescaling` layer to scale input values (initially in the `[0, 255]`\n",
" range) to the `[-1, 1]` range.\n",
"- We add a `Dropout` layer before the classification layer, for regularization.\n",
"- We make sure to pass `training=False` when calling the base model, so that\n",
Expand All @@ -782,7 +782,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "682e09fefdf6"
"id": "35d00d5e5722"
},
"outputs": [],
"source": [
Expand All @@ -799,15 +799,11 @@
"inputs = keras.Input(shape=(150, 150, 3))\n",
"x = data_augmentation(inputs) # Apply random data augmentation\n",
"\n",
"# Pre-trained Xception weights requires that input be normalized\n",
"# from (0, 255) to a range (-1., +1.), the normalization layer\n",
"# does the following, outputs = (inputs - mean) / sqrt(var)\n",
"norm_layer = keras.layers.Normalization()\n",
"mean = np.array([127.5] * 3)\n",
"var = mean ** 2\n",
"# Scale inputs to [-1, +1]\n",
"x = norm_layer(x)\n",
"norm_layer.set_weights([mean, var])\n",
"# Pre-trained Xception weights requires that input be scaled\n",
"# from (0, 255) to a range of (-1., +1.), the rescaling layer\n",
"# outputs: `(inputs * scale) + offset`\n",
"scale_layer = keras.layers.Rescaling(scale=1 / 127.5, offset=-1)\n",
"x = scale_layer(x)\n",
"\n",
"# The base model contains batchnorm layers. We want to keep them in inference mode\n",
"# when we unfreeze the base model for fine-tuning, so we make sure that the\n",
Expand Down

0 comments on commit 5677c3d

Please sign in to comment.