From b1fa63c85cebead51c1d33e46c3fa1e6e4d05b90 Mon Sep 17 00:00:00 2001 From: Yash Katariya Date: Fri, 25 Sep 2020 13:04:17 -0700 Subject: [PATCH] Generate _toc.yaml and make cell_id generation deterministic (#264) * Generate _toc.yaml * changes * changes * changes * Add PyYAML * Delete * Add toc * changes * Hash the content with cell_count * Use cell_id variable * Changes --- requirements.txt | 1 + scripts/generate_tf_guides.py | 89 +++++--- tf/_toc.yaml | 27 ++- tf/custom_callback.ipynb | 56 ++--- tf/custom_layers_and_models.ipynb | 126 +++++------ tf/customizing_what_happens_in_fit.ipynb | 54 ++--- tf/functional.ipynb | 156 +++++++------- tf/masking_and_padding.ipynb | 68 +++--- tf/preprocessing_layers.ipynb | 72 +++---- tf/rnn.ipynb | 92 ++++---- tf/save_and_serialize.ipynb | 128 +++++------ tf/sequential_model.ipynb | 96 ++++----- tf/train_and_evaluate.ipynb | 202 +++++++++--------- tf/training_keras_models_on_cloud.ipynb | 70 +++--- tf/transfer_learning.ipynb | 92 ++++---- tf/writing_a_training_loop_from_scratch.ipynb | 84 ++++---- 16 files changed, 716 insertions(+), 697 deletions(-) diff --git a/requirements.txt b/requirements.txt index b0f4384774..5aefc291b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ sphinx~=3.0.3 black==19.10b0 pathlib tf-nightly~=2.3.0.dev20200610 +PyYAML diff --git a/scripts/generate_tf_guides.py b/scripts/generate_tf_guides.py index f2f17e13b2..5c3e2bdd67 100644 --- a/scripts/generate_tf_guides.py +++ b/scripts/generate_tf_guides.py @@ -2,26 +2,53 @@ import tutobooks import copy import json -import random +import hashlib import string import re +import yaml +# The order of CONFIG is also used to generate the _toc.yaml for tensorflow.org. CONFIG = [ + { + "title": "The Sequential model", + "source_name": "sequential_model", + "target_name": "sequential_model", + }, { "title": "The Functional API", "source_name": "functional_api", "target_name": "functional", }, { - "title": "Training & evaluation with the built-in methods", + "title": "Training and evaluation with the built-in methods", "source_name": "training_with_built_in_methods", "target_name": "train_and_evaluate", }, { - "title": "Making new Layers & Models via subclassing", + "title": "Making new Layers and Models via subclassing", "source_name": "making_new_layers_and_models_via_subclassing", "target_name": "custom_layers_and_models", }, + { + "title": "Save and load Keras models", + "source_name": "serialization_and_saving", + "target_name": "save_and_serialize", + }, + { + "title": "Working with preprocessing layers", + "source_name": "preprocessing_layers", + "target_name": "preprocessing_layers", + }, + { + "title": "Customize what happens in Model.fit", + "source_name": "customizing_what_happens_in_fit", + "target_name": "customizing_what_happens_in_fit", + }, + { + "title": "Writing a training loop from scratch", + "source_name": "writing_a_training_loop_from_scratch", + "target_name": "writing_a_training_loop_from_scratch", + }, { "title": "Recurrent Neural Networks (RNN) with Keras", "source_name": "working_with_rnns", @@ -32,46 +59,21 @@ "source_name": "understanding_masking_and_padding", "target_name": "masking_and_padding", }, - { - "title": "Save and load Keras models", - "source_name": "serialization_and_saving", - "target_name": "save_and_serialize", - }, { "title": "Writing your own callbacks", "source_name": "writing_your_own_callbacks", "target_name": "custom_callback", }, { - "title": "Writing a training loop from scratch", - "source_name": "writing_a_training_loop_from_scratch", - "target_name": "writing_a_training_loop_from_scratch", - }, - { - "title": "Transfer learning & fine-tuning", + "title": "Transfer learning and fine-tuning", "source_name": "transfer_learning", "target_name": "transfer_learning", }, - { - "title": "The Sequential model", - "source_name": "sequential_model", - "target_name": "sequential_model", - }, - { - "title": "Customizing what happens in `fit()`", - "source_name": "customizing_what_happens_in_fit", - "target_name": "customizing_what_happens_in_fit", - }, { "title": "Training Keras models with TensorFlow Cloud", "source_name": "training_keras_models_on_cloud", "target_name": "training_keras_models_on_cloud", }, - { - "title": "Working with preprocessing layers", - "source_name": "preprocessing_layers", - "target_name": "preprocessing_layers", - }, ] @@ -205,8 +207,13 @@ def generate_single_tf_guide(source_dir, target_dir, title, source_name, target_ buttons["source"][i] = buttons["source"][i].replace("SOURCE_NAME", source_name) header_cells.append(buttons) cells = header_cells + cells + + cell_count = 0 for cell in cells: - cell["metadata"]["id"] = random_id() + cell_count += 1 + str_to_hash = f"{cell_count} {cell['source']}" + cell_id = hashlib.sha256(str_to_hash.encode('utf-8')).hexdigest() + cell["metadata"]["id"] = cell_id[:12] notebook = {} for key in TF_IPYNB_BASE.keys(): @@ -259,14 +266,26 @@ def generate_single_tf_guide(source_dir, target_dir, title, source_name, target_ f.close() -def random_id(): - length = 12 - letters = string.ascii_lowercase + string.ascii_uppercase + "0123456789" - return "".join(random.choice(letters) for i in range(length)) +def generate_toc(target_dir): + target_dir = Path(target_dir) + + toc = [] + for config in CONFIG: + toc.append( + { + "title": config["title"], + "path": str(Path("/guide/keras") / config["target_name"]), + } + ) + toc_dict = {"toc": toc} + + with open(str(target_dir / "_toc.yaml"), "w") as toc_file: + yaml.dump(toc_dict, toc_file, sort_keys=False) def generate_tf_guides(): - random.seed(1337) + generate_toc(target_dir="../tf") + for entry in CONFIG: generate_single_tf_guide( source_dir="../guides/ipynb/", diff --git a/tf/_toc.yaml b/tf/_toc.yaml index 7a861caa23..52b8634227 100644 --- a/tf/_toc.yaml +++ b/tf/_toc.yaml @@ -1,28 +1,27 @@ toc: -- title: "Sequential API" +- title: The Sequential model path: /guide/keras/sequential_model -- title: "Keras functional API" +- title: The Functional API path: /guide/keras/functional -- title: "Train and evaluate" +- title: Training and evaluation with the built-in methods path: /guide/keras/train_and_evaluate -- title: "Write custom layers and models" +- title: Making new Layers and Models via subclassing path: /guide/keras/custom_layers_and_models -- title: "Save and serialize models" +- title: Save and load Keras models path: /guide/keras/save_and_serialize -- title: "Working with preprocessing layers" +- title: Working with preprocessing layers path: /guide/keras/preprocessing_layers -- title: "Customizing what happens in fit" +- title: Customize what happens in Model.fit path: /guide/keras/customizing_what_happens_in_fit -- title: "Writing a training loop from scratch" +- title: Writing a training loop from scratch path: /guide/keras/writing_a_training_loop_from_scratch -- title: "Keras Recurrent Neural Networks" +- title: Recurrent Neural Networks (RNN) with Keras path: /guide/keras/rnn -- title: "Masking and padding" +- title: Masking and padding with Keras path: /guide/keras/masking_and_padding -- title: "Write custom callbacks" +- title: Writing your own callbacks path: /guide/keras/custom_callback -- title: "Transfer learning" +- title: Transfer learning and fine-tuning path: /guide/keras/transfer_learning -- title: "Training Keras models with TensorFlow Cloud" +- title: Training Keras models with TensorFlow Cloud path: /guide/keras/training_keras_models_on_cloud - status: new diff --git a/tf/custom_callback.ipynb b/tf/custom_callback.ipynb index ab4d646640..a82844e287 100644 --- a/tf/custom_callback.ipynb +++ b/tf/custom_callback.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "SlT4CrDemeqz" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "Nw5BqikBFR8J" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,7 +38,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "bgYNefYV3toR" + "id": "d201e826ab29" }, "source": [ "# Writing your own callbacks" @@ -48,7 +48,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "oM80XSuTIvJl" + "id": "71699af85d2d" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "dm6Tx5DcPg1o" + "id": "d75eb2e25f36" }, "source": [ "## Introduction\n", @@ -90,7 +90,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "6UxOi7EEE6Q9" + "id": "b3600ee25c8e" }, "source": [ "## Setup" @@ -101,7 +101,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "QDjgZ3jSko2k" + "id": "4dadb6688663" }, "outputs": [], "source": [ @@ -113,7 +113,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "UVpW1Q0YjwH4" + "id": "42676f705fc8" }, "source": [ "## Keras callbacks overview\n", @@ -135,7 +135,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "swt9nVKBw2Zb" + "id": "46945bdf5056" }, "source": [ "## An overview of callback methods\n", @@ -176,7 +176,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "dpE2CcBRVisf" + "id": "82f2370418a1" }, "source": [ "## A basic example\n", @@ -190,7 +190,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "lcsY3ImU6n4A" + "id": "7350ea602e50" }, "outputs": [], "source": [ @@ -210,7 +210,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Em39zXsmb6br" + "id": "044db5f2dc6f" }, "source": [ "Then, load the MNIST data for training and testing from Keras datasets API:" @@ -221,7 +221,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "kAh1Hsy79P0t" + "id": "f8826736a184" }, "outputs": [], "source": [ @@ -241,7 +241,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "IPVzRdrXuQYo" + "id": "b9acd50b2215" }, "source": [ "Now, define a simple custom callback that logs:\n", @@ -258,7 +258,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "7zaOKC7dpK7n" + "id": "cc9888d28e79" }, "outputs": [], "source": [ @@ -324,7 +324,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "gIiFWfxsNkyp" + "id": "8184bd3a76c2" }, "source": [ "Let's try it out:" @@ -335,7 +335,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Ey9oQfhHERRs" + "id": "75f7aa1edac6" }, "outputs": [], "source": [ @@ -361,7 +361,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "mdVErv1llBq0" + "id": "02113b8677eb" }, "source": [ "### Usage of `logs` dict\n", @@ -374,7 +374,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "lAC03ymKbxZN" + "id": "2c5e71af7abe" }, "outputs": [], "source": [ @@ -417,7 +417,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "qH2GuBD9Pl7H" + "id": "742d62e5394a" }, "source": [ "## Usage of `self.model` attribute\n", @@ -445,7 +445,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "gkR5WkzikUzX" + "id": "7eb29d3ed752" }, "source": [ "## Examples of Keras callback applications" @@ -455,7 +455,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "8lbTowW8Tbk8" + "id": "2d1d29d99fa5" }, "source": [ "### Early stopping at minimum loss\n", @@ -473,7 +473,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "QTU1xXEs9VES" + "id": "5d2acd79cecd" }, "outputs": [], "source": [ @@ -538,7 +538,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "9aOhw3UB85Va" + "id": "939ecfbe0383" }, "source": [ "### Learning rate scheduling\n", @@ -554,7 +554,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "oFwr7dO76pJr" + "id": "71c752b248c0" }, "outputs": [], "source": [ @@ -621,7 +621,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "9tTLuI6Xz4yv" + "id": "c9be225b57f1" }, "source": [ "### Built-in Keras callbacks\n", diff --git a/tf/custom_layers_and_models.ipynb b/tf/custom_layers_and_models.ipynb index f573d889bf..1442b4d7dd 100644 --- a/tf/custom_layers_and_models.ipynb +++ b/tf/custom_layers_and_models.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "nHFrZ6mSVgbp" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "ixegCbFZ2T25" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,17 +38,17 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "awqPPX0Q8vYT" + "id": "e2d97c7e31aa" }, "source": [ - "# Making new Layers & Models via subclassing" + "# Making new Layers and Models via subclassing" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "LTqJ1ikKyceC" + "id": "4e352274064f" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "kqt8kOlhsGft" + "id": "8d4ac441b1fc" }, "source": [ "## Setup" @@ -82,7 +82,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "kq8IIIox9WJE" + "id": "4e7dce39dd1d" }, "outputs": [], "source": [ @@ -94,7 +94,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "TD27aTpsLn5u" + "id": "7b363673d96c" }, "source": [ "## The `Layer` class: the combination of state (weights) and some computation\n", @@ -111,7 +111,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "4RUhruXa4ZKb" + "id": "59b8317dbd3c" }, "outputs": [], "source": [ @@ -136,7 +136,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "cgY2wswCFLPZ" + "id": "dac8fb03a642" }, "source": [ "You would use a layer by calling it on some tensor input(s), much like a Python\n", @@ -148,7 +148,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "vTII3wVU6qtj" + "id": "cdcd15d5e68a" }, "outputs": [], "source": [ @@ -162,7 +162,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "LJ7OoUjWeZhh" + "id": "382960020a56" }, "source": [ "Note that the weights `w` and `b` are automatically tracked by the layer upon\n", @@ -174,7 +174,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "3V7wJau8UFOX" + "id": "d3d875af9465" }, "outputs": [], "source": [ @@ -185,7 +185,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Q7wND7JrVpdN" + "id": "ec9d72aa7538" }, "source": [ "Note you also have access to a quicker shortcut for adding weight to a layer:\n", @@ -197,7 +197,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "TTIVB70FWNOt" + "id": "168548eba841" }, "outputs": [], "source": [ @@ -223,7 +223,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "dYhuJy6yTiS9" + "id": "070ea9b4db6c" }, "source": [ "## Layers can have non-trainable weights\n", @@ -240,7 +240,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "tI2G8cI2jZ13" + "id": "7c4cb404145f" }, "outputs": [], "source": [ @@ -266,7 +266,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "RpWSJZzHmQSp" + "id": "40f5b74d3d87" }, "source": [ "It's part of `layer.weights`, but it gets categorized as a non-trainable weight:" @@ -277,7 +277,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "o4D4QQwjFeyy" + "id": "3d4db4ef4fa4" }, "outputs": [], "source": [ @@ -292,7 +292,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ncwHsnN9B8k9" + "id": "fe6942aff7c6" }, "source": [ "## Best practice: deferring weight creation until the shape of the inputs is known\n", @@ -306,7 +306,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "LtrJblaWx8tc" + "id": "275b68d5ea9f" }, "outputs": [], "source": [ @@ -326,7 +326,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "SpyO7nCow04a" + "id": "5ebcacebb348" }, "source": [ "In many cases, you may not know in advance the size of your inputs, and you\n", @@ -342,7 +342,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Rb83DJButaho" + "id": "118c899f427e" }, "outputs": [], "source": [ @@ -369,7 +369,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "cyBR7y8E8ufQ" + "id": "78061e0583c6" }, "source": [ "The `__call__()` method of your layer will automatically run build the first time\n", @@ -381,7 +381,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "GU2r8uYYE0fk" + "id": "fb08b1a45d22" }, "outputs": [], "source": [ @@ -396,7 +396,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "m8bIg1hJr89U" + "id": "ddd7e8b22641" }, "source": [ "## Layers are recursively composable\n", @@ -414,7 +414,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "0qOJqRwQUEr9" + "id": "9561cbf2fc60" }, "outputs": [], "source": [ @@ -447,7 +447,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "dZqxaNW99EJ4" + "id": "496736d98a62" }, "source": [ "## The `add_loss()` method\n", @@ -462,7 +462,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "1lQhORgjB17D" + "id": "084d56602ca4" }, "outputs": [], "source": [ @@ -481,7 +481,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "fePyIm48QiYw" + "id": "5009ff0d1feb" }, "source": [ "These losses (including those created by any inner layer) can be retrieved via\n", @@ -495,7 +495,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "JRIe9672VW9A" + "id": "5bff6d59aea7" }, "outputs": [], "source": [ @@ -523,7 +523,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "52XfTTOBrP81" + "id": "36751ebe3363" }, "source": [ "In addition, the `loss` property also contains regularization losses created\n", @@ -535,7 +535,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "sfVWUn7P88QF" + "id": "9327d3b581f8" }, "outputs": [], "source": [ @@ -562,7 +562,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "0urVzA9Wo9mC" + "id": "99d502b8899c" }, "source": [ "These losses are meant to be taken into account when writing training loops,\n", @@ -591,7 +591,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "yvIheYprhlyH" + "id": "7fa2db4a631d" }, "source": [ "For a detailed guide about writing training loops, see the\n", @@ -606,7 +606,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "QU8eqT5Fw96x" + "id": "7c534372bf8a" }, "outputs": [], "source": [ @@ -632,7 +632,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "84S8HSkjhgiC" + "id": "c753fcbc1818" }, "source": [ "## The `add_metric()` method\n", @@ -651,7 +651,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "fke2DxeEcShL" + "id": "85dad61dc160" }, "outputs": [], "source": [ @@ -680,7 +680,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "RgzCcpvK9Y6i" + "id": "cd8807cb9cbc" }, "source": [ "Metrics tracked in this way are accessible via `layer.metrics`:" @@ -691,7 +691,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "erSyqdogfTmU" + "id": "475df7270265" }, "outputs": [], "source": [ @@ -709,7 +709,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "PmHqPSYEzldb" + "id": "9eda5113fd18" }, "source": [ "Just like for `add_loss()`, these metrics are tracked by `fit()`:" @@ -720,7 +720,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "jt7oF8jvZNZl" + "id": "97f767613953" }, "outputs": [], "source": [ @@ -743,7 +743,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "gFFPGW3EWDIN" + "id": "4bdbac3f6c85" }, "source": [ "## You can optionally enable serialization on your layers\n", @@ -758,7 +758,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "bqDVRZRBvNVe" + "id": "b359ed5289a8" }, "outputs": [], "source": [ @@ -795,7 +795,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "GPxhREfRdhww" + "id": "78b207f7acbc" }, "source": [ "Note that the `__init__()` method of the base `Layer` class takes some keyword\n", @@ -809,7 +809,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "qKTZxIcqHlie" + "id": "00a3432cd28c" }, "outputs": [], "source": [ @@ -847,7 +847,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "M5gqgEqCXh57" + "id": "ad5d100cc969" }, "source": [ "If you need more flexibility when deserializing the layer from its config, you\n", @@ -867,7 +867,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "DUwJd8BP35dX" + "id": "741c6d134d65" }, "source": [ "## Privileged `training` argument in the `call()` method\n", @@ -887,7 +887,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "iYoTcDOudWKh" + "id": "67ca741d0cfb" }, "outputs": [], "source": [ @@ -906,7 +906,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "z1iQXP6n3ZYo" + "id": "5284e22677da" }, "source": [ "## Privileged `mask` argument in the `call()` method\n", @@ -931,7 +931,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "8abHGdFNGSP4" + "id": "bf87358118de" }, "source": [ "## The `Model` class\n", @@ -974,7 +974,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "aBm6fvCdhz04" + "id": "78539e55de0c" }, "source": [ "```python\n", @@ -1005,7 +1005,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "jvl5puMkWGvP" + "id": "b817a4de8c5d" }, "source": [ "## Putting it all together: an end-to-end example\n", @@ -1032,7 +1032,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "01ZsIuuBAILh" + "id": "18842173f875" }, "outputs": [], "source": [ @@ -1112,7 +1112,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "N56qaB3WDjPV" + "id": "40384d934b3c" }, "source": [ "Let's write a simple training loop on MNIST:" @@ -1123,7 +1123,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "GOvvMRyUWIKs" + "id": "c37fef01d4bc" }, "outputs": [], "source": [ @@ -1168,7 +1168,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "8Nx70GcuadnN" + "id": "65e5faeb0029" }, "source": [ "Note that since the VAE is subclassing `Model`, it features built-in training\n", @@ -1180,7 +1180,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "IqW0JbRiujG1" + "id": "1e98ba7ebdb8" }, "outputs": [], "source": [ @@ -1196,7 +1196,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "u0qLp0el7h9a" + "id": "42ee3169e70c" }, "source": [ "## Beyond object-oriented development: the Functional API\n", @@ -1215,7 +1215,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "jsqCR9VsMiP9" + "id": "b8fe39f892c7" }, "outputs": [], "source": [ @@ -1255,7 +1255,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ABJHWFNCaqjt" + "id": "0f4db7df7eb5" }, "source": [ "For more information, make sure to read the [Functional API guide](https://www.tensorflow.org/guide/keras/functional/)." diff --git a/tf/customizing_what_happens_in_fit.ipynb b/tf/customizing_what_happens_in_fit.ipynb index 7ee63fa960..9e62c7bee3 100644 --- a/tf/customizing_what_happens_in_fit.ipynb +++ b/tf/customizing_what_happens_in_fit.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "zsP5VpOpSivq" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "gvvApNeEfvLL" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,17 +38,17 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "c4TihRiHIKee" + "id": "a5620ee4049e" }, "source": [ - "# Customizing what happens in `fit()`" + "# Customize what happens in Model.fit" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "IzXFRryV6yxq" + "id": "0a56ffedf331" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "2ZBxGJZEXaWr" + "id": "7ebb4e65ef9b" }, "source": [ "## Introduction\n", @@ -108,7 +108,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "LM1yZO4J3zyO" + "id": "2849e371b9b6" }, "source": [ "## Setup\n", @@ -120,7 +120,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "fzsg0aNp6yuN" + "id": "4dadb6688663" }, "outputs": [], "source": [ @@ -132,7 +132,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "UsYEdOFRbXmA" + "id": "9022333acaa7" }, "source": [ "## A first simple example\n", @@ -166,7 +166,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "4d1wDUe4ReTa" + "id": "060c8bf4150d" }, "outputs": [], "source": [ @@ -197,7 +197,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "VitQSwBvcGIe" + "id": "c9d2cc7a7014" }, "source": [ "Let's try this out:" @@ -208,7 +208,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Zk9UnwB6gdES" + "id": "5e6bd7b554f6" }, "outputs": [], "source": [ @@ -230,7 +230,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "VwWN0qnQacU9" + "id": "9c096e07c2f5" }, "source": [ "## Going lower-level\n", @@ -258,7 +258,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "u2fnMF4QYQFN" + "id": "2308abf5fe7d" }, "outputs": [], "source": [ @@ -315,7 +315,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "j1tE4yrX22rl" + "id": "f451e382c6a8" }, "source": [ "## Supporting `sample_weight` & `class_weight`\n", @@ -335,7 +335,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "L4j0uOhTfBjh" + "id": "5401fb151fcb" }, "outputs": [], "source": [ @@ -392,7 +392,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "YXvaogkBppfg" + "id": "03000c5590db" }, "source": [ "## Providing your own evaluation step\n", @@ -406,7 +406,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "2txiE4ZsCtjI" + "id": "999edb22c50e" }, "outputs": [], "source": [ @@ -441,7 +441,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "9BjyyxuepxgM" + "id": "9e6a662e6588" }, "source": [ "## Wrapping up: an end-to-end GAN example\n", @@ -463,7 +463,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "uFcxFFOFm7xb" + "id": "6748db01dc7c" }, "outputs": [], "source": [ @@ -506,7 +506,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "CMwvS2v5pvGM" + "id": "801e8dd0c92a" }, "source": [ "Here's a feature-complete GAN class, overriding `compile()` to use its own signature,\n", @@ -518,7 +518,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "7hFGTUQysnjl" + "id": "bc3fb4111393" }, "outputs": [], "source": [ @@ -584,7 +584,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "sXmPJp4mErKa" + "id": "095c499a6149" }, "source": [ "Let's test-drive it:" @@ -595,7 +595,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "q1ZTGksVTeL0" + "id": "46832f2077ac" }, "outputs": [], "source": [ @@ -624,7 +624,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "qkvwajnLUxEs" + "id": "2ed211016c96" }, "source": [ "The ideas behind deep learning are simple, so why should their implementation be painful?" diff --git a/tf/functional.ipynb b/tf/functional.ipynb index 58ec08dd85..3d9a11ed54 100644 --- a/tf/functional.ipynb +++ b/tf/functional.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "TxKLUkX0vyOY" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "x6tzSnWQ36xg" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,7 +38,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "B0Oz5eGSQw4z" + "id": "da6087fbd570" }, "source": [ "# The Functional API" @@ -48,7 +48,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "zZVZtQb1wMhD" + "id": "d169f4a559d5" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "p9kY2uRS66MD" + "id": "8d4ac441b1fc" }, "source": [ "## Setup" @@ -82,7 +82,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "MqZmJeOHNKXc" + "id": "ec52be14e686" }, "outputs": [], "source": [ @@ -96,7 +96,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "eA9P5NdRbOmm" + "id": "871fbb54ea07" }, "source": [ "## Introduction\n", @@ -132,7 +132,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "gsmCV6ZKuaY7" + "id": "8d477c91955a" }, "outputs": [], "source": [ @@ -143,7 +143,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "NvBKYoJcXJUP" + "id": "13c14d993620" }, "source": [ "The shape of the data is set as a 784-dimensional vector.\n", @@ -158,7 +158,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "t25nNlHHHlXQ" + "id": "e4732e8e279b" }, "outputs": [], "source": [ @@ -170,7 +170,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "dVFTVLD5bZHF" + "id": "971bf8b5588f" }, "source": [ "The `inputs` that is returned contains information about the shape and `dtype`\n", @@ -183,7 +183,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "IWPU7wVJZKPq" + "id": "ee96c179846a" }, "outputs": [], "source": [ @@ -194,7 +194,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "qeTi8d5ku0fm" + "id": "866eee86d63e" }, "source": [ "Here's the dtype:" @@ -205,7 +205,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "C8I1q4dJjBwM" + "id": "480be92067f3" }, "outputs": [], "source": [ @@ -216,7 +216,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "T467cBsVjdOD" + "id": "6c93172cdfba" }, "source": [ "You create a new node in the graph of layers by calling a layer on this `inputs`\n", @@ -228,7 +228,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "wyenwQRPMqTn" + "id": "b50da8b1c28d" }, "outputs": [], "source": [ @@ -240,7 +240,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "miEzNBJqkoT1" + "id": "0f36afe42ff3" }, "source": [ "The \"layer call\" action is like drawing an arrow from \"inputs\" to this layer\n", @@ -255,7 +255,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "vzNmZW9N7A7k" + "id": "463d5cd0c484" }, "outputs": [], "source": [ @@ -267,7 +267,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "TENSOucbIMmP" + "id": "e379f089b044" }, "source": [ "At this point, you can create a `Model` by specifying its inputs and outputs\n", @@ -279,7 +279,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "BtW89IuXz3wo" + "id": "7820cc2209a6" }, "outputs": [], "source": [ @@ -290,7 +290,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "6t5CLy9OyjN0" + "id": "c9aa111852d3" }, "source": [ "Let's check out what the model summary looks like:" @@ -301,7 +301,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "rWVpy0TfDSav" + "id": "4949ab8242e8" }, "outputs": [], "source": [ @@ -312,7 +312,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "f17rFH0M6yic" + "id": "99ab8535d6c3" }, "source": [ "You can also plot the model as a graph:" @@ -323,7 +323,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "28GLymOChQpt" + "id": "6872f1b1b8b8" }, "outputs": [], "source": [ @@ -334,7 +334,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "dFYTnwIv7rLg" + "id": "6d9880136879" }, "source": [ "And, optionally, display the input and output shapes of each layer\n", @@ -346,7 +346,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "R2R8jGXLQPcP" + "id": "aa14046d3388" }, "outputs": [], "source": [ @@ -357,7 +357,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "JFsbjjDf63PU" + "id": "71969f9c91bb" }, "source": [ "This figure and the code are almost identical. In the code version,\n", @@ -371,7 +371,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "NF7DVUblYmkp" + "id": "4b93b2089279" }, "source": [ "## Training, evaluation, and inference\n", @@ -389,7 +389,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "WoPcTOZCDTZz" + "id": "e61366d54487" }, "outputs": [], "source": [ @@ -415,7 +415,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "RtWubSBwYOgY" + "id": "2e13d7168c86" }, "source": [ "For further reading, see the [training and evaluation](https://www.tensorflow.org/guide/keras/train_and_evaluate/) guide." @@ -425,7 +425,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "kfTa6tOQ2mkR" + "id": "26991ef4dbbb" }, "source": [ "## Save and serialize\n", @@ -448,7 +448,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "mgfkJP6zKMp7" + "id": "7e5e48669225" }, "outputs": [], "source": [ @@ -462,7 +462,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "65dBoRYAv2JD" + "id": "cfe2a761139b" }, "source": [ "For details, read the model [serialization & saving](\n", @@ -473,7 +473,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "EVmeee2PQixr" + "id": "b747517364a9" }, "source": [ "## Use the same graph of layers to define multiple models\n", @@ -492,7 +492,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Lyba7ZR68pdI" + "id": "f9924d8c9ed3" }, "outputs": [], "source": [ @@ -522,7 +522,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "J7h2Pz9rHJ6s" + "id": "e87d4185b652" }, "source": [ "Here, the decoding architecture is strictly symmetrical\n", @@ -537,7 +537,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "jS6a22AtFxcX" + "id": "9c746c1a0b79" }, "source": [ "## All models are callable, just like layers\n", @@ -556,7 +556,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "QuaWMdfWYd0W" + "id": "862ac58e928b" }, "outputs": [], "source": [ @@ -593,7 +593,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "xZBNAzElaF9R" + "id": "0f77623d9cd5" }, "source": [ "As you can see, the model can be nested: a model can contain sub-models\n", @@ -608,7 +608,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "2lmeBmf9JOHY" + "id": "3bb36b630e5d" }, "outputs": [], "source": [ @@ -634,7 +634,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ZkAo4M1f9oGl" + "id": "447a319b73a6" }, "source": [ "## Manipulate complex graph topologies\n", @@ -666,7 +666,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "BbB98HIWtgT7" + "id": "49009e53da63" }, "outputs": [], "source": [ @@ -711,7 +711,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "OusdT4Fx0ubX" + "id": "ee2735b3eff1" }, "source": [ "Now plot the model:" @@ -722,7 +722,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "xLLv6Sng5IbS" + "id": "52c4dc6fd93e" }, "outputs": [], "source": [ @@ -733,7 +733,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "8dzSHzcZzaPc" + "id": "907c119d04a4" }, "source": [ "When compiling this model, you can assign different losses to each output.\n", @@ -746,7 +746,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "RNBUDfuMHNCJ" + "id": "3e1acef07668" }, "outputs": [], "source": [ @@ -764,7 +764,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "G9nfDLR2XxVx" + "id": "e780b99b133a" }, "source": [ "Since the output layers have different names, you could also specify\n", @@ -776,7 +776,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "cjjgoZNAkimQ" + "id": "84ce034debf2" }, "outputs": [], "source": [ @@ -794,7 +794,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "0qyEvexNnk0M" + "id": "845b20ca3c9d" }, "source": [ "Train the model by passing lists of NumPy arrays of inputs and targets:" @@ -805,7 +805,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "4ErZIZfR7rEq" + "id": "ae5ff9364b19" }, "outputs": [], "source": [ @@ -830,7 +830,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "jUgWn45jTSkj" + "id": "3c87f1fbe7aa" }, "source": [ "When calling fit with a `Dataset` object, it should yield either a\n", @@ -845,7 +845,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "cQadpYwhtmQe" + "id": "64ada3f80484" }, "source": [ "### A toy ResNet model\n", @@ -864,7 +864,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "UGBNHK7yU8zf" + "id": "bfa8b7503813" }, "outputs": [], "source": [ @@ -895,7 +895,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "mZlT1xTn8SHQ" + "id": "05aefc66c54f" }, "source": [ "Plot the model:" @@ -906,7 +906,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "6dU6pgsJusu4" + "id": "ef7ac19c83be" }, "outputs": [], "source": [ @@ -917,7 +917,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "s6cqAuvSfP5I" + "id": "4f0883eae520" }, "source": [ "Now train the model:" @@ -928,7 +928,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "WLrIrc4u41d7" + "id": "4e1c7b530071" }, "outputs": [], "source": [ @@ -953,7 +953,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "iBF4FPYKvkMy" + "id": "e7f35a9a1061" }, "source": [ "## Shared layers\n", @@ -978,7 +978,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "HQbCeLm4SIyV" + "id": "4b8e6a4f3e88" }, "outputs": [], "source": [ @@ -1000,7 +1000,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "tnYHFRNNAKCT" + "id": "b4f193a74581" }, "source": [ "## Extract and reuse nodes in the graph of layers\n", @@ -1021,7 +1021,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "LizyVyleqviq" + "id": "8bdaa209ccbe" }, "outputs": [], "source": [ @@ -1032,7 +1032,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "PKrTHqggNliw" + "id": "874ef4b4de49" }, "source": [ "And these are the intermediate activations of the model,\n", @@ -1044,7 +1044,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "RAiGhPjGyS7w" + "id": "391817839937" }, "outputs": [], "source": [ @@ -1055,7 +1055,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "QBJbX7tfyUyN" + "id": "e91a9dc2f5b0" }, "source": [ "Use these features to create a new feature-extraction model that returns\n", @@ -1067,7 +1067,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "GDXbgd7KpXjo" + "id": "36a450517b63" }, "outputs": [], "source": [ @@ -1081,7 +1081,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "SeTbV8d6NcL9" + "id": "f2ac248fe202" }, "source": [ "This comes in handy for tasks like\n", @@ -1093,7 +1093,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "HNbKS3uXjN0v" + "id": "c894ba891064" }, "source": [ "## Extend the API using custom layers\n", @@ -1123,7 +1123,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "ptMTt8v6t9Nz" + "id": "1d9faf1f622a" }, "outputs": [], "source": [ @@ -1156,7 +1156,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ZWvTlcIN3z6g" + "id": "b8933568358c" }, "source": [ "For serialization support in your custom layer, define a `get_config`\n", @@ -1168,7 +1168,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "BBzoCWOeoaTT" + "id": "b22a134918a2" }, "outputs": [], "source": [ @@ -1207,7 +1207,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "HlzrWMLvqCle" + "id": "015abf7d0508" }, "source": [ "Optionally, implement the class method `from_config(cls, config)` which is used\n", @@ -1224,7 +1224,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "aIOquCbOsKoH" + "id": "b4ead34e01dd" }, "source": [ "## When to use the functional API\n", @@ -1333,7 +1333,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "EzhwdXaXoGNq" + "id": "72992d4ed462" }, "source": [ "## Mix-and-match API styles\n", @@ -1353,7 +1353,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "LDs1ClHRb8QU" + "id": "3c6221508766" }, "outputs": [], "source": [ @@ -1399,7 +1399,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "uRDzMJLc1pO1" + "id": "41f42eb2a9c0" }, "source": [ "You can use any subclassed layer or model in the functional API\n", @@ -1428,7 +1428,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Z07EOUIlE2U8" + "id": "3deb90222d05" }, "outputs": [], "source": [ diff --git a/tf/masking_and_padding.ipynb b/tf/masking_and_padding.ipynb index fd9ce95797..ede335fd6d 100644 --- a/tf/masking_and_padding.ipynb +++ b/tf/masking_and_padding.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "43jwc4WWFlX8" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "Qrt4EBOoEdK9" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,7 +38,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "xfGxtsVcQxgi" + "id": "8bd329a4bbca" }, "source": [ "# Masking and padding with Keras" @@ -48,7 +48,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Feax0Tese2RQ" + "id": "8b208d0913b8" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "3oufr5Cersl1" + "id": "8d4ac441b1fc" }, "source": [ "## Setup" @@ -82,7 +82,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "zKJvGvYwBa0g" + "id": "ec52be14e686" }, "outputs": [], "source": [ @@ -96,7 +96,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "xuFEv4OQF72T" + "id": "3731f3ff3670" }, "source": [ "## Introduction\n", @@ -116,7 +116,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "IQ5ZkRSRhyWO" + "id": "ac6b121d6be0" }, "source": [ "## Padding sequence data\n", @@ -157,7 +157,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "TjEewzpJh73D" + "id": "bb64fb185a05" }, "outputs": [], "source": [ @@ -184,7 +184,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "t4Q7gy7L4s70" + "id": "03092b2da690" }, "source": [ "## Masking\n", @@ -204,7 +204,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ZqpQV0o8DBr9" + "id": "6103601e5fff" }, "source": [ "## Mask-generating layers: `Embedding` and `Masking`\n", @@ -219,7 +219,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Q95DlBPHoQeU" + "id": "b2363b293483" }, "outputs": [], "source": [ @@ -243,7 +243,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "nNBkmPhq3RfD" + "id": "17e4bdb563b2" }, "source": [ "As you can see from the printed result, the mask is a 2D boolean tensor with shape\n", @@ -255,7 +255,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "AtPB4dLZUGIS" + "id": "cf11a0399fcf" }, "source": [ "## Mask propagation in the Functional API and Sequential API\n", @@ -274,7 +274,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "FVAWcJ0sneMb" + "id": "0adbecda288a" }, "outputs": [], "source": [ @@ -287,7 +287,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "eyDysRIRwwVv" + "id": "a8ac6481a1d5" }, "source": [ "This is also the case for the following Functional API model:" @@ -298,7 +298,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "8R8Dt439Aapv" + "id": "f374ab06743d" }, "outputs": [], "source": [ @@ -313,7 +313,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "LGbEUB8jymZO" + "id": "2f2c4b96ecb5" }, "source": [ "## Passing mask tensors directly to layers" @@ -323,7 +323,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Nw2mR5pIXpXd" + "id": "11dccb581014" }, "source": [ "Layers that can handle masks (such as the `LSTM` layer) have a `mask` argument in their\n", @@ -341,7 +341,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "8BFpQQgXq29d" + "id": "1955aa63896b" }, "outputs": [], "source": [ @@ -371,7 +371,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "WTxq7rPlRfrY" + "id": "b04dd330f848" }, "source": [ "## Supporting masking in your custom layers" @@ -381,7 +381,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "VkdQqAPVJw9Q" + "id": "8451a1a8ff27" }, "source": [ "Sometimes, you may need to write layers that generate a mask (like `Embedding`), or\n", @@ -403,7 +403,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "wI2v7KXNQdjK" + "id": "a06fb2194c0d" }, "outputs": [], "source": [ @@ -431,7 +431,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "XQzfEwOKTtEa" + "id": "282b867dcd95" }, "source": [ "Here is another example of a `CustomEmbedding` layer that is capable of generating a\n", @@ -443,7 +443,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "PRWBEte4q50h" + "id": "e760655cd39c" }, "outputs": [], "source": [ @@ -484,7 +484,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "oKfpNebmTdtv" + "id": "bb34149eb837" }, "source": [ "## Opting-in to mask propagation on compatible layers\n", @@ -508,7 +508,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "dDvmdCTi4XjM" + "id": "895c35534d06" }, "outputs": [], "source": [ @@ -526,7 +526,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Pgx32suiga4W" + "id": "a2e1e0a81995" }, "source": [ "You can now use this custom layer in-between a mask-generating layer (like `Embedding`)\n", @@ -539,7 +539,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "ROxAhMD6zZot" + "id": "486e39e9a9a7" }, "outputs": [], "source": [ @@ -556,7 +556,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "MDRJnq4XJuNO" + "id": "55ab9c02f4ba" }, "source": [ "## Writing layers that need mask information\n", @@ -577,7 +577,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Zu3HIeNtOzPS" + "id": "7809df539882" }, "outputs": [], "source": [ @@ -602,7 +602,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ssZdrK1pP01M" + "id": "6373f43bbe18" }, "source": [ "## Summary\n", diff --git a/tf/preprocessing_layers.ipynb b/tf/preprocessing_layers.ipynb index 864c0449e9..baaed1c458 100644 --- a/tf/preprocessing_layers.ipynb +++ b/tf/preprocessing_layers.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "cGG1wQApauZS" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "sUB5jlFr3kgy" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,7 +38,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "oRGFbB5fzMUf" + "id": "6e083398b477" }, "source": [ "# Working with preprocessing layers" @@ -48,7 +48,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "NgMGFoKC2WRN" + "id": "64010bd23c2e" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "pVqgZXXBlTZS" + "id": "5387d1418bf5" }, "source": [ "## Keras preprocessing layers\n", @@ -90,7 +90,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "uowOLuTbyDPq" + "id": "5808993b2aa9" }, "source": [ "## Available preprocessing layers\n", @@ -144,7 +144,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "lpq3ZpzDsWBe" + "id": "672e84af6eb7" }, "source": [ "## The `adapt()` method\n", @@ -171,7 +171,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "7P69xglpBgnX" + "id": "e05c8fc4d032" }, "outputs": [], "source": [ @@ -192,7 +192,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "8tLVQsmcFNC2" + "id": "d43b8246b8a3" }, "source": [ "The `adapt()` method takes either a Numpy array or a `tf.data.Dataset` object. In the\n", @@ -204,7 +204,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "RVN9HUHjwVsO" + "id": "74ef94620592" }, "outputs": [], "source": [ @@ -228,7 +228,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "37GWkB2UC3px" + "id": "7619914dfb40" }, "source": [ "In addition, adaptable layers always expose an option to directly set state via\n", @@ -247,7 +247,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "xfQxnLdcx0Kf" + "id": "76aeb9346838" }, "outputs": [], "source": [ @@ -262,7 +262,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "owP370LIedBg" + "id": "3cd07d2533da" }, "source": [ "## Preprocessing data before the model or inside the model\n", @@ -303,7 +303,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "gPtiZ0E8AQfS" + "id": "4a45cb81797f" }, "source": [ "## Benefits of doing preprocessing inside the model at inference time\n", @@ -340,7 +340,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "G81ZqzYOfS70" + "id": "ff9bad6ba7d5" }, "source": [ "## Quick recipes\n", @@ -356,7 +356,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "FWTK8s8Yxbuq" + "id": "a621c2645ae6" }, "outputs": [], "source": [ @@ -391,7 +391,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "dvY4WK17LQQA" + "id": "51d369f0310f" }, "source": [ "You can see a similar setup in action in the example\n", @@ -402,7 +402,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "WGaBM5MioeBq" + "id": "a79a1c48b2b7" }, "source": [ "### Normalizing numerical features" @@ -413,7 +413,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "5mN71unrIf8y" + "id": "f5a7c8f6270b" }, "outputs": [], "source": [ @@ -442,7 +442,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "z6a3gJL7tMbS" + "id": "62685d477010" }, "source": [ "### Encoding string categorical features via one-hot encoding" @@ -453,7 +453,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "nfUWbzxFrepl" + "id": "36303d995404" }, "outputs": [], "source": [ @@ -478,7 +478,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "BwaPm3zPD0JA" + "id": "3d88c64d9b33" }, "source": [ "Note that index 0 is reserved for missing values (which you should specify as the empty\n", @@ -494,7 +494,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "FhQ1JmJUFCKJ" + "id": "dc8af3e290df" }, "source": [ "### Encoding integer categorical features via one-hot encoding" @@ -505,7 +505,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "U0B242pIHZ1C" + "id": "e55f069cbdf5" }, "outputs": [], "source": [ @@ -530,7 +530,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "oOeT14cFO7sc" + "id": "82830d172b7f" }, "source": [ "Note that index 0 is reserved for missing values (which you should specify as the value\n", @@ -546,7 +546,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Kpkz20kZeqTD" + "id": "8fbfaa6ab3e2" }, "source": [ "### Applying the hashing trick to an integer categorical feature\n", @@ -564,7 +564,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "LNHfHTdQd4kJ" + "id": "2def8456f905" }, "outputs": [], "source": [ @@ -584,7 +584,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Vz0SkEM1JusG" + "id": "df69b434d327" }, "source": [ "### Encoding text as a sequence of token indices\n", @@ -597,7 +597,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "8dMscYkebZ1G" + "id": "a689d9dcf6ab" }, "outputs": [], "source": [ @@ -635,7 +635,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "6QDLJE3xYrGg" + "id": "a84d4f2ec0ef" }, "source": [ "You can see the `TextVectorization` layer in action, combined with an `Embedding` mode,\n", @@ -651,7 +651,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "eoaxL82yXTe8" + "id": "28c2f2ff61fb" }, "source": [ "### Encoding text as a dense matrix of ngrams with multi-hot encoding\n", @@ -664,7 +664,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "RF785LWOL6bq" + "id": "b62472e32529" }, "outputs": [], "source": [ @@ -706,7 +706,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "qUsUte9T1UAa" + "id": "336a4d3426ed" }, "source": [ "### Encoding text as a dense matrix of ngrams with TF-IDF weighting\n", @@ -719,7 +719,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "hn1PLShTFgjH" + "id": "cdf16938fe7c" }, "outputs": [], "source": [ diff --git a/tf/rnn.ipynb b/tf/rnn.ipynb index 59f0d58b12..ca10d6695c 100644 --- a/tf/rnn.ipynb +++ b/tf/rnn.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "aEadCeEDRAwT" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "KCVfE64hxAKU" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,7 +38,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "C2yuOHQioQ8O" + "id": "6ca65cda94c8" }, "source": [ "# Recurrent Neural Networks (RNN) with Keras" @@ -48,7 +48,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "kTyLadYgB0yQ" + "id": "1e4938db0e55" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "F3KPBjQVvj8g" + "id": "6873211b02d4" }, "source": [ "## Introduction\n", @@ -99,7 +99,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "yHvJ5r5CjARa" + "id": "b3600ee25c8e" }, "source": [ "## Setup" @@ -110,7 +110,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "6VgYTLkxKP3b" + "id": "71c626bbac35" }, "outputs": [], "source": [ @@ -124,7 +124,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "17LzNefTGph2" + "id": "4041a2e9b310" }, "source": [ "## Built-in RNN layers: a simple example" @@ -134,7 +134,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "DKzF3Al1mieW" + "id": "98e0c38cf95d" }, "source": [ "There are three built-in RNN layers in Keras:\n", @@ -161,7 +161,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "7pcBNWzeoOXJ" + "id": "a5617759e54e" }, "outputs": [], "source": [ @@ -183,7 +183,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Fl8trfaufeit" + "id": "cb8ef33660a0" }, "source": [ "Built-in RNNs support a number of useful features:\n", @@ -202,7 +202,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "WY9iNskdeA64" + "id": "43aa4e4f344d" }, "source": [ "## Outputs and states\n", @@ -222,7 +222,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "WSXadShDSX0c" + "id": "c3294dec91e4" }, "outputs": [], "source": [ @@ -244,7 +244,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "X6JuGJMFm4Hp" + "id": "266812a04bb2" }, "source": [ "In addition, a RNN layer can return its final internal state(s). The returned states\n", @@ -269,7 +269,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "fRCgvkMnBuhs" + "id": "ece412e6afbe" }, "outputs": [], "source": [ @@ -306,7 +306,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "HopK92mEPlBZ" + "id": "e97a845a372a" }, "source": [ "## RNN layers and RNN cells\n", @@ -341,7 +341,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "bkMUh6EMJTal" + "id": "60b3b721d500" }, "source": [ "## Cross-batch statefulness\n", @@ -397,7 +397,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "J7uLCS6qLMec" + "id": "19e72be49a42" }, "outputs": [], "source": [ @@ -419,7 +419,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "cQ9dPyIBKaOj" + "id": "ec7c316b19a1" }, "source": [ "### RNN State Reuse\n", @@ -430,7 +430,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "z2tMh9OC1hdD" + "id": "3cb7a8ac464a" }, "source": [ "The recorded states of the RNN layer are not included in the `layer.weights()`. If you\n", @@ -449,7 +449,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "PTqlHiihZ7Sm" + "id": "009c5b393adf" }, "outputs": [], "source": [ @@ -471,7 +471,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "cM0nvnH1fet6" + "id": "66c1d7f1ccba" }, "source": [ "## Bidirectional RNNs\n", @@ -490,7 +490,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "rORHu4gLl2G0" + "id": "8cea1781a0c2" }, "outputs": [], "source": [ @@ -509,7 +509,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "fUrIWlnem4BM" + "id": "5747cd1a0ed8" }, "source": [ "Under the hood, `Bidirectional` will copy the RNN layer passed in, and flip the\n", @@ -527,7 +527,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "8L6fCAFGAR8i" + "id": "18a254dfaa73" }, "source": [ "## Performance optimization and CuDNN kernels\n", @@ -560,7 +560,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "HXYbeaWhkHxc" + "id": "fb8de09c4343" }, "source": [ "### Using CuDNN kernels when available\n", @@ -576,7 +576,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "FFbhu19CbiJx" + "id": "e88aab9e73c7" }, "outputs": [], "source": [ @@ -615,7 +615,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "9jSqX9vtPhdr" + "id": "dcde82cb14d6" }, "source": [ "Let's load the MNIST dataset:" @@ -626,7 +626,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "4dsLsMyTLP1q" + "id": "98292f8e71a9" }, "outputs": [], "source": [ @@ -641,7 +641,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ceEhX5V23fJq" + "id": "443e5458284f" }, "source": [ "Let's create a model instance and train it.\n", @@ -656,7 +656,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "vNpfvfZJEiga" + "id": "f85b57b010e5" }, "outputs": [], "source": [ @@ -678,7 +678,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "si2nUusiGCoL" + "id": "99ea5495e375" }, "source": [ "Now, let's compare to a model that does not use the CuDNN kernel:" @@ -689,7 +689,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "B70OtcEsHBOZ" + "id": "d4bdff02e617" }, "outputs": [], "source": [ @@ -709,7 +709,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "x8nq1mi62Ndl" + "id": "90fc64fbd4ea" }, "source": [ "When running on a machine with a NVIDIA GPU and CuDNN installed,\n", @@ -729,7 +729,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "xdWbJzKWBP5l" + "id": "7e33c62b6029" }, "outputs": [], "source": [ @@ -749,7 +749,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "cNMTAGuPzwT4" + "id": "2f940b73a2a6" }, "source": [ "## RNNs with list/dict inputs, or nested inputs\n", @@ -774,7 +774,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "xa7D0r2TARZ5" + "id": "f78dc4c1c516" }, "source": [ "### Define a custom cell that supports nested input/output" @@ -784,7 +784,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "mh0Nyf30iKy2" + "id": "199faf57f0c5" }, "source": [ "See [Making new Layers & Models via subclassing](https://www.tensorflow.org/guide/keras/custom_layers_and_models/)\n", @@ -796,7 +796,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "LpdLadWWVWik" + "id": "451cfd5f0cc4" }, "outputs": [], "source": [ @@ -848,7 +848,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "JLOJYNziLqoB" + "id": "51355b4089d2" }, "source": [ "### Build a RNN model with nested input/output\n", @@ -862,7 +862,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "sjgvGoOlmAaB" + "id": "b2eba7a248eb" }, "outputs": [], "source": [ @@ -894,7 +894,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "V9EqJlcNzFSU" + "id": "452a99c63b7c" }, "source": [ "### Train the model with randomly generated data\n", @@ -908,7 +908,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "hrLD0wraOdp6" + "id": "3987993cb7be" }, "outputs": [], "source": [ @@ -926,7 +926,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "MCadQ5oBVJ2e" + "id": "b51e87780b0f" }, "source": [ "With the Keras `keras.layers.RNN` layer, You are only expected to define the math\n", diff --git a/tf/save_and_serialize.ipynb b/tf/save_and_serialize.ipynb index 15fd1b3682..11d614fbda 100644 --- a/tf/save_and_serialize.ipynb +++ b/tf/save_and_serialize.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "U1gtl722Mvju" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "SfF9AnjBfz22" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,7 +38,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "gqTrNGttwSFE" + "id": "394e705afdd5" }, "source": [ "# Save and load Keras models" @@ -48,7 +48,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ltPlYTaLGGOl" + "id": "60de82f6bcea" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "mxEKhPbck9E8" + "id": "fa3c30941890" }, "source": [ "## Introduction\n", @@ -101,7 +101,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "2NbT80eTSUng" + "id": "feed3cb00608" }, "source": [ "## The short answer to saving & loading\n", @@ -129,7 +129,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "CUBallmpGiEb" + "id": "41fbd6a3290a" }, "source": [ "## Setup" @@ -140,7 +140,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "XDrZ6eEK8ekt" + "id": "abff67cc7505" }, "outputs": [], "source": [ @@ -153,7 +153,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "huHUg5WkAAOb" + "id": "09c134c6f58a" }, "source": [ "## Whole-model saving & loading\n", @@ -185,7 +185,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ZnMsqSBTGkkG" + "id": "5d260a6d0cdd" }, "source": [ "### SavedModel format\n", @@ -198,7 +198,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "maonibKMsFZ4" + "id": "4d910eb33378" }, "outputs": [], "source": [ @@ -238,7 +238,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Bko0kniAGdvE" + "id": "3f8e96c8a949" }, "source": [ "#### What the SavedModel contains\n", @@ -252,7 +252,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "mH9gZk3nwEHK" + "id": "47be41998ac5" }, "outputs": [], "source": [ @@ -263,7 +263,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "CtPPIAXT8BFS" + "id": "7e9ecb6fe81a" }, "source": [ "The model architecture, and training configuration\n", @@ -300,7 +300,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "f9WnESi1jRVL" + "id": "8c5be8eb50e5" }, "outputs": [], "source": [ @@ -337,7 +337,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "HzSTywDB8VW8" + "id": "b799483e35e5" }, "source": [ "As seen in the example above, the loader dynamically creates a new model class\n", @@ -348,7 +348,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "gugRIvOIfqWh" + "id": "9ce118f08539" }, "source": [ "### Keras H5 format\n", @@ -365,7 +365,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "QJbjxsX8XdS4" + "id": "5a0dfcf90f17" }, "outputs": [], "source": [ @@ -396,7 +396,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "OjcY3tXyZyk4" + "id": "675baa87dfe4" }, "source": [ "#### Limitations\n", @@ -422,7 +422,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "WsrIjTX1Z0lj" + "id": "96f5daf26eb7" }, "source": [ "## Saving the architecture\n", @@ -440,7 +440,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ooF7V8jN9nt9" + "id": "a45a21771bcf" }, "source": [ "### Configuration of a Sequential model or Functional API model\n", @@ -458,7 +458,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "hBE4H3XIDY91" + "id": "07623392f9e9" }, "source": [ "#### `get_config()` and `from_config()`\n", @@ -478,7 +478,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "oy2orPhGTaHZ" + "id": "0e6385d07d27" }, "outputs": [], "source": [ @@ -491,7 +491,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "RXF09I6yvGV2" + "id": "ea7872aadd7d" }, "source": [ "**Sequential model example:**" @@ -502,7 +502,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "ufQ9SuxM15lE" + "id": "36b8c6a174b5" }, "outputs": [], "source": [ @@ -515,7 +515,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "UrHHIVpEKSsT" + "id": "e6509757ce2b" }, "source": [ "**Functional model example:**" @@ -526,7 +526,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "8oNDjRR6fO4G" + "id": "4f49340ff336" }, "outputs": [], "source": [ @@ -541,7 +541,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "S6J7jcVOpdPR" + "id": "a1a183180766" }, "source": [ "#### `to_json()` and `tf.keras.models.model_from_json()`\n", @@ -558,7 +558,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "ieWE6kPB1B8X" + "id": "2b9a9bf23522" }, "outputs": [], "source": [ @@ -571,7 +571,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "y5znOcN8keia" + "id": "04214f35e34e" }, "source": [ "### Custom objects\n", @@ -606,7 +606,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "aDOvu5chswcH" + "id": "7516f3fb5d3c" }, "outputs": [], "source": [ @@ -620,7 +620,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "znB5p8XgNCi0" + "id": "28e979f23c83" }, "source": [ "Note that this method has several drawbacks:\n", @@ -642,7 +642,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "SmYeVMs9Rs5o" + "id": "8bfb9c653b51" }, "source": [ "#### Defining the config methods\n", @@ -663,7 +663,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "jCOlbIz9cmWD" + "id": "f5cb928ed5d3" }, "outputs": [], "source": [ @@ -700,7 +700,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "sr5X5chZaxYp" + "id": "76aeb91c0e1e" }, "source": [ "#### Registering the custom object\n", @@ -728,7 +728,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "C2MdYdOM5u4N" + "id": "8a757bc52a5f" }, "source": [ "#### Custom layer and function example" @@ -739,7 +739,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "J9Ia1JUuCjy7" + "id": "d714f3a99012" }, "outputs": [], "source": [ @@ -790,7 +790,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "0o16KQFlItCZ" + "id": "05e02e8349c8" }, "source": [ "### In-memory model cloning\n", @@ -807,7 +807,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "f2wq1Dgi9eZU" + "id": "812cb93a30c2" }, "outputs": [], "source": [ @@ -819,7 +819,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "rRdRJgbG8Zq7" + "id": "1f8f862e443f" }, "source": [ "## Saving & loading only the model's weights values\n", @@ -837,7 +837,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "WBxXT0h7yxAA" + "id": "907f60d28973" }, "source": [ "### APIs for in-memory weight transfer\n", @@ -860,7 +860,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "4eIvCxdjmy6e" + "id": "a9f78162427e" }, "outputs": [], "source": [ @@ -881,7 +881,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "KACleccO1um5" + "id": "7e257429b186" }, "source": [ "***Transfering weights from one model to another model with a\n", @@ -893,7 +893,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "WUV42tpJDicL" + "id": "75be1147b413" }, "outputs": [], "source": [ @@ -939,7 +939,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "4vTWVjoCuVP6" + "id": "450837e1dd20" }, "source": [ "***The case of stateless layers***\n", @@ -954,7 +954,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "totUrgZcDAYa" + "id": "7b79e7593754" }, "outputs": [], "source": [ @@ -982,7 +982,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "MLde8G1QVux2" + "id": "1e28dd5a9538" }, "source": [ "### APIs for saving weights to disk & loading them back\n", @@ -1009,7 +1009,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "za1W82BZuskI" + "id": "01fb4134c3c2" }, "source": [ "### TF Checkpoint format\n", @@ -1022,7 +1022,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "LzCUDB1dkiec" + "id": "abbd79695980" }, "outputs": [], "source": [ @@ -1048,7 +1048,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "xZwwjjEg7zQ2" + "id": "160774248d82" }, "source": [ "#### Format details\n", @@ -1071,7 +1071,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "9Otfdbha2TvY" + "id": "f77c2cb05abc" }, "outputs": [], "source": [ @@ -1092,7 +1092,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "WH6Xqhxo35q0" + "id": "8d49652a9106" }, "source": [ "#### Transfer learning example\n", @@ -1108,7 +1108,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "qjeCsRvSzqMJ" + "id": "95b270d038e8" }, "outputs": [], "source": [ @@ -1171,7 +1171,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "0sa9EmwUaZBT" + "id": "32a55c2b9430" }, "source": [ "It is generally recommended to stick to the same API for building models. If you\n", @@ -1184,7 +1184,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "eWj6jE9sz7yQ" + "id": "7d75461f527f" }, "source": [ "The next question is, how can weights be saved and loaded to different models\n", @@ -1199,7 +1199,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "9b1R9zCAelVe" + "id": "cf634d8db6cc" }, "outputs": [], "source": [ @@ -1239,7 +1239,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "xHJ2LictZScl" + "id": "577a6251b115" }, "source": [ "### HDF5 format\n", @@ -1258,7 +1258,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "DhrCy09yfqXQ" + "id": "56dff373e74a" }, "outputs": [], "source": [ @@ -1279,7 +1279,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "T8VX8hFyI9Hg" + "id": "60d8185d803d" }, "source": [ "Note that changing `layer.trainable` may result in a different\n", @@ -1291,7 +1291,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "YTV4GHHReOFE" + "id": "573c5a9cd489" }, "outputs": [], "source": [ @@ -1321,7 +1321,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "GqYcgjA7yYG4" + "id": "9e8934a16393" }, "source": [ "#### Transfer learning example\n", @@ -1338,7 +1338,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "9dfEwwyiWMln" + "id": "eb22a5e3d192" }, "outputs": [], "source": [ diff --git a/tf/sequential_model.ipynb b/tf/sequential_model.ipynb index 85080e3de5..e78abeaa4b 100644 --- a/tf/sequential_model.ipynb +++ b/tf/sequential_model.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "RpTAZsYweEXs" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "F1Utzdxri4Xd" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,7 +38,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "C3IRYgz2642R" + "id": "3e19705694d6" }, "source": [ "# The Sequential model" @@ -48,7 +48,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "7AEVkPfh5AQ8" + "id": "defbb10e8ae3" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "fFzQH86UozfT" + "id": "8d4ac441b1fc" }, "source": [ "## Setup" @@ -82,7 +82,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "DwPpajdypoWB" + "id": "0472bf67b2bf" }, "outputs": [], "source": [ @@ -95,7 +95,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "xCFim9gUL80f" + "id": "80f7713c6b92" }, "source": [ "## When to use a Sequential model\n", @@ -111,7 +111,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "mFFogqksyI6U" + "id": "f536515be229" }, "outputs": [], "source": [ @@ -132,7 +132,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "N0U3MqyEgCnQ" + "id": "7d81502d9753" }, "source": [ "is equivalent to this function:" @@ -143,7 +143,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Vf4wsWxFjYzp" + "id": "7059a8890f72" }, "outputs": [], "source": [ @@ -161,7 +161,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "KzUDitLg7K6q" + "id": "cdf6d2932c31" }, "source": [ "A Sequential model is **not appropriate** when:\n", @@ -177,7 +177,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "TzVOg3fvbcVm" + "id": "c5706d9f8eb8" }, "source": [ "## Creating a Sequential model\n", @@ -191,7 +191,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "CHEPLwmuasfp" + "id": "8b3eee00f80d" }, "outputs": [], "source": [ @@ -208,7 +208,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "5KXsqVNQRoWq" + "id": "1939a7a4a66c" }, "source": [ "Its layers are accessible via the `layers` attribute:" @@ -219,7 +219,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "J3PY2TD4yRfl" + "id": "49c0448b6da2" }, "outputs": [], "source": [ @@ -230,7 +230,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "SEv6PmunUrP7" + "id": "b4c7957e9913" }, "source": [ "You can also create a Sequential model incrementally via the `add()` method:" @@ -241,7 +241,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "HhMI6INo3oxS" + "id": "d54fde401054" }, "outputs": [], "source": [ @@ -255,7 +255,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "LUbAAAvcsRrO" + "id": "d16278f5a1dc" }, "source": [ "Note that there's also a corresponding `pop()` method to remove layers:\n", @@ -267,7 +267,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "xQ9Ws8oN1kMY" + "id": "e89f35b73979" }, "outputs": [], "source": [ @@ -279,7 +279,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "qSuDPqGh2rml" + "id": "99cb1c9a7c7a" }, "source": [ "Also note that the Sequential constructor accepts a `name` argument, just like\n", @@ -292,7 +292,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "jliNtW04KX03" + "id": "068c2f82e7cb" }, "outputs": [], "source": [ @@ -306,7 +306,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "2Ol9NU0Ai9lb" + "id": "a6247ff17d3a" }, "source": [ "## Specifying the input shape in advance\n", @@ -321,7 +321,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "GUKAOqSj1TLC" + "id": "373ecbb5c6bd" }, "outputs": [], "source": [ @@ -333,7 +333,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "U1vHCDF0sLoV" + "id": "da150335961e" }, "source": [ "It creates its weights the first time it is called on an input, since the shape\n", @@ -345,7 +345,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "rGdUovoPw8Nc" + "id": "bf28829ce193" }, "outputs": [], "source": [ @@ -359,7 +359,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "bevblaWJparr" + "id": "e50f21c5f247" }, "source": [ "Naturally, this also applies to Sequential models. When you instantiate a\n", @@ -374,7 +374,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Jg70mY2X9Qbg" + "id": "04479960526c" }, "outputs": [], "source": [ @@ -402,7 +402,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "abHu1ZDoaIHv" + "id": "2837e3d2c798" }, "source": [ "Once a model is \"built\", you can call its `summary()` method to display its\n", @@ -414,7 +414,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "wSmwWv9HeHEe" + "id": "1368bd27f679" }, "outputs": [], "source": [ @@ -425,7 +425,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "CKAG4rhwhV0m" + "id": "08cf1da27edb" }, "source": [ "However, it can be very useful when building a Sequential model incrementally\n", @@ -439,7 +439,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "pu6moCwEwMoy" + "id": "e3d2024cfeeb" }, "outputs": [], "source": [ @@ -454,7 +454,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "1B0AxcKk9VmV" + "id": "3d965e3761a8" }, "source": [ "Note that the `Input` object is not displayed as part of `model.layers`, since\n", @@ -466,7 +466,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Y9ofFMe4x1CM" + "id": "8e3b0d58e7ed" }, "outputs": [], "source": [ @@ -477,7 +477,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "P75NE8lMCSBy" + "id": "8a057b1baf72" }, "source": [ "A simple alternative is to just pass an `input_shape` argument to your first\n", @@ -489,7 +489,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "qIqPW5tJgMQ6" + "id": "1c6ab83d68ea" }, "outputs": [], "source": [ @@ -503,7 +503,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "phEplz8Lo0OO" + "id": "40c14619d283" }, "source": [ "Models built with a predefined input shape like this always have weights (even\n", @@ -517,7 +517,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "weirCNbDnMrN" + "id": "843f6b6505b3" }, "source": [ "## A common debugging workflow: `add()` + `summary()`\n", @@ -533,7 +533,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "PCWudoMLAESt" + "id": "46bfb8f7dc6e" }, "outputs": [], "source": [ @@ -570,7 +570,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "LF8ltQ1VzU9L" + "id": "a2d3335a90fa" }, "source": [ "Very practical, right?\n", @@ -581,7 +581,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "jW6ODCnNkNL4" + "id": "fb8136a95fb8" }, "source": [ "## What to do once you have a model\n", @@ -601,7 +601,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "EEWToX0vtFJE" + "id": "608f3b03669c" }, "source": [ "## Feature extraction with a Sequential model\n", @@ -619,7 +619,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "r8mC4fCuSyOQ" + "id": "a5888d753301" }, "outputs": [], "source": [ @@ -645,7 +645,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "FkbqCdWf9KFX" + "id": "4abef35355d3" }, "source": [ "Here's a similar example that only extract features from one layer:" @@ -656,7 +656,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "XjM4weB4ei6u" + "id": "fc404c7ac90e" }, "outputs": [], "source": [ @@ -681,7 +681,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "NtIg2KROuTZV" + "id": "ab25cedd111e" }, "source": [ "## Transfer learning with a Sequential model\n", @@ -750,7 +750,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "uhrp6aEVQQ40" + "id": "fcffc33b61e5" }, "source": [ "That's about all you need to know about Sequential models!\n", diff --git a/tf/train_and_evaluate.ipynb b/tf/train_and_evaluate.ipynb index dbef913355..f65f77e6c4 100644 --- a/tf/train_and_evaluate.ipynb +++ b/tf/train_and_evaluate.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "tKk4EI3t2zID" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "LJHABcjvRgNy" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,17 +38,17 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "vg23XJ7poxqk" + "id": "fb291b62b1aa" }, "source": [ - "# Training & evaluation with the built-in methods" + "# Training and evaluation with the built-in methods" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "OC6o2vgFteOc" + "id": "b1820d9bdfb9" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "J6hnSS5omGYB" + "id": "8d4ac441b1fc" }, "source": [ "## Setup" @@ -82,7 +82,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "LPAR13g3289c" + "id": "0472bf67b2bf" }, "outputs": [], "source": [ @@ -95,7 +95,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ZbiRoKUawJ51" + "id": "e2c78442fa34" }, "source": [ "## Introduction\n", @@ -125,7 +125,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "FHNdmeHu1Giv" + "id": "4e270faa413e" }, "source": [ "## API overview: a first end-to-end example\n", @@ -144,7 +144,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "II8YruI1Dq8g" + "id": "170a6a18b2a3" }, "outputs": [], "source": [ @@ -160,7 +160,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Csh8cc8mWTrV" + "id": "e6d5724a90ab" }, "source": [ "Here's what the typical end-to-end workflow looks like, consisting of:\n", @@ -177,7 +177,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "rf4QiojU4kgH" + "id": "8b55b3903edb" }, "outputs": [], "source": [ @@ -201,7 +201,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ixUOrWekOr9H" + "id": "77a84eb1985b" }, "source": [ "We specify the training configuration (optimizer, loss, metrics):" @@ -212,7 +212,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "AqBbBS5m36rF" + "id": "26a7f1819796" }, "outputs": [], "source": [ @@ -229,7 +229,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "tS30q56SyhNJ" + "id": "ef28150b1eaa" }, "source": [ "We call `fit()`, which will train the model by slicing the data into \"batches\" of size\n", @@ -242,7 +242,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "3Hq30luGHv6F" + "id": "0b92f67b105e" }, "outputs": [], "source": [ @@ -263,7 +263,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "201DiBVrCRP8" + "id": "0a1b698c6e39" }, "source": [ "The returned \"history\" object holds a record of the loss values and metric values\n", @@ -275,7 +275,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "KiGsxYdOLNuF" + "id": "a20b8f5b9fcc" }, "outputs": [], "source": [ @@ -286,7 +286,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "WerJNjWt1tX8" + "id": "6105b646df66" }, "source": [ "We evaluate the model on the test data via `evaluate()`:" @@ -297,7 +297,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Yk2ZryVJUl1O" + "id": "69f524a93f9d" }, "outputs": [], "source": [ @@ -317,7 +317,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "vpw2uIMaWxC3" + "id": "f19d074eb88c" }, "source": [ "Now, let's review each piece of this workflow in detail." @@ -327,7 +327,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "o3XOHv7OELAo" + "id": "f3669f026d14" }, "source": [ "## The `compile()` method: specifying a loss, metrics, and an optimizer\n", @@ -343,7 +343,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "iVowq4njRtRJ" + "id": "eb7a8deb494c" }, "outputs": [], "source": [ @@ -358,7 +358,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "3EQzQXdqOsRu" + "id": "c4061c977ac3" }, "source": [ "The `metrics` argument should be a list -- your model can have any number of metrics.\n", @@ -377,7 +377,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "bkHuXh4uTdOj" + "id": "6444839ff300" }, "outputs": [], "source": [ @@ -392,7 +392,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "f67OGnZFmT62" + "id": "5493ab963254" }, "source": [ "For later reuse, let's put our model definition and compile step in functions; we will\n", @@ -404,7 +404,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "JxAkonpb8KIw" + "id": "31c3e3c70f06" }, "outputs": [], "source": [ @@ -431,7 +431,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "3lKFY4v3hTth" + "id": "21b19c0a6a85" }, "source": [ "### Many built-in optimizers, losses, and metrics are available\n", @@ -465,7 +465,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "4Ksz1cDrEAuZ" + "id": "d7abc0339980" }, "source": [ "### Custom losses\n", @@ -481,7 +481,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "tRoViEtNBHbC" + "id": "cc4edd47bb5a" }, "outputs": [], "source": [ @@ -501,7 +501,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "8v5AYTUywEOe" + "id": "25b9fa7941ca" }, "source": [ "If you need a loss function that takes in parameters beside `y_true` and `y_pred`, you\n", @@ -525,7 +525,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "F6UqgEvGwdoC" + "id": "b09463a8c568" }, "outputs": [], "source": [ @@ -551,7 +551,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "A46g3HPgf6hN" + "id": "b2141cc075a6" }, "source": [ "### Custom metrics\n", @@ -579,7 +579,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "nE0Xz945XSC3" + "id": "05d6a6e7022d" }, "outputs": [], "source": [ @@ -618,7 +618,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "upuYsZJfuEoM" + "id": "4bca8e959cda" }, "source": [ "### Handling losses and metrics that don't fit the standard signature\n", @@ -640,7 +640,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Y1baigwmLOrH" + "id": "b494d47437a0" }, "outputs": [], "source": [ @@ -674,7 +674,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "wOqG5z0IjJlq" + "id": "aaebb5829011" }, "source": [ "You can do the same for logging metric values, using `add_metric()`:" @@ -685,7 +685,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "aoWBItbV8f7F" + "id": "aa58091be092" }, "outputs": [], "source": [ @@ -722,7 +722,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "BpwJOJASvoJu" + "id": "f3c18154d057" }, "source": [ "In the [Functional API](https://www.tensorflow.org/guide/keras/functional/),\n", @@ -737,7 +737,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "meU4louIhIg9" + "id": "0e19afe78b3a" }, "outputs": [], "source": [ @@ -762,7 +762,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "AQ8fiku4cmpA" + "id": "b06d48035369" }, "source": [ "Note that when you pass losses via `add_loss()`, it becomes possible to call\n", @@ -778,7 +778,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "V3nY6WRRyhpJ" + "id": "d56d2c504258" }, "outputs": [], "source": [ @@ -807,7 +807,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "o97oNuVxtpYO" + "id": "0698f3c98cbe" }, "source": [ "You can use it in a model with two inputs (input data & targets), compiled without a\n", @@ -819,7 +819,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "0EuZf3c1e9AT" + "id": "0f6842f2bbe6" }, "outputs": [], "source": [ @@ -844,7 +844,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "CfOObGXhOJ3X" + "id": "328b021aa6b8" }, "source": [ "For more information about training multi-input models, see the section **Passing data\n", @@ -855,7 +855,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "xUkOCJDATraQ" + "id": "0536882b969c" }, "source": [ "### Automatically setting apart a validation holdout set\n", @@ -882,7 +882,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "an0uov0TM4Wb" + "id": "232fd59c751b" }, "outputs": [], "source": [ @@ -894,7 +894,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "EioWqf2jt213" + "id": "42969af7ce01" }, "source": [ "## Training & evaluation from tf.data Datasets\n", @@ -921,7 +921,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "jBqAFwb53f3Y" + "id": "3bf4ded224f8" }, "outputs": [], "source": [ @@ -951,7 +951,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "65TiYoapycoS" + "id": "421d16914ce3" }, "source": [ "Note that the Dataset is reset at the end of each epoch, so it can be reused of the\n", @@ -971,7 +971,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "kTq0J5kR7prZ" + "id": "273c5dff16b4" }, "outputs": [], "source": [ @@ -989,7 +989,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "FnId4XruET87" + "id": "f2dcd180da7b" }, "source": [ "### Using a validation dataset\n", @@ -1002,7 +1002,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Q427EbNMzCWu" + "id": "bf4f3d78e69a" }, "outputs": [], "source": [ @@ -1023,7 +1023,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "TgqZ6sPeesU1" + "id": "2e7f0ebf5f1d" }, "source": [ "At the end of each epoch, the model will iterate over the validation dataset and\n", @@ -1040,7 +1040,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Cr1O9rOcy4n3" + "id": "f47342fed069" }, "outputs": [], "source": [ @@ -1068,7 +1068,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "HmmQ1cShpOI6" + "id": "67b4418e9f26" }, "source": [ "Note that the validation dataset will be reset after each use (so that you will always\n", @@ -1084,7 +1084,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "qq7qvl3SYTY1" + "id": "8160beb766a0" }, "source": [ "## Other input formats supported\n", @@ -1155,7 +1155,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "mCJ6F03ifjgg" + "id": "2a28343b1967" }, "source": [ "## Using sample weighting and class weighting\n", @@ -1172,7 +1172,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "BDd7IzeZxGa6" + "id": "f234a9a75b6d" }, "source": [ "### Class weights\n", @@ -1192,7 +1192,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "5BdyLdy6oPBu" + "id": "9929d26d91b8" }, "source": [ "Here's a NumPy example where we use class weights or sample weights to\n", @@ -1205,7 +1205,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "PHqYIqumDclU" + "id": "f1844f2329a6" }, "outputs": [], "source": [ @@ -1235,7 +1235,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "4GWLjuCNoceI" + "id": "ce27221fad08" }, "source": [ "### Sample weights\n", @@ -1263,7 +1263,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "UhLclV5iZ3yZ" + "id": "f9819d647793" }, "outputs": [], "source": [ @@ -1279,7 +1279,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "vJwG7hMoRC8W" + "id": "eae5837c5f56" }, "source": [ "Here's a matching `Dataset` example:" @@ -1290,7 +1290,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "B7BVM2tylp36" + "id": "c870f3f0c66c" }, "outputs": [], "source": [ @@ -1312,7 +1312,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "RvM6jxrYntmv" + "id": "3963bfa348b0" }, "source": [ "## Passing data to multi-input, multi-output models\n", @@ -1333,7 +1333,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "iPVuPI7DBXeG" + "id": "5f958449a057" }, "outputs": [], "source": [ @@ -1360,7 +1360,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "97WpnPJrlzrn" + "id": "df3ed34fe78b" }, "source": [ "Let's plot this model, so you can clearly see what we're doing here (note that the\n", @@ -1372,7 +1372,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Y3xo79iAnAXW" + "id": "ac8c1baca9e3" }, "outputs": [], "source": [ @@ -1383,7 +1383,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "eBnT0COkDd2a" + "id": "4d979e89b335" }, "source": [ "At compilation time, we can specify different losses to different outputs, by passing\n", @@ -1395,7 +1395,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "bNMC7XrPB6i2" + "id": "9655c0084d70" }, "outputs": [], "source": [ @@ -1409,7 +1409,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "58rpl0LviTHQ" + "id": "f5fc73405283" }, "source": [ "If we only passed a single loss function to the model, the same loss function would be\n", @@ -1423,7 +1423,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "2ULuVsQMUsFM" + "id": "b4c0c6c564bc" }, "outputs": [], "source": [ @@ -1444,7 +1444,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ZWYxwqbMPr9R" + "id": "4dd9fb0343cc" }, "source": [ "Since we gave names to our output layers, we could also specify per-output losses and\n", @@ -1456,7 +1456,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "N6wGr1FNNTiN" + "id": "42cb75110fc3" }, "outputs": [], "source": [ @@ -1480,7 +1480,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "nyjiJe5Ppg2p" + "id": "bfd95ac0dd8b" }, "source": [ "We recommend the use of explicit names and dicts if you have more than 2 outputs.\n", @@ -1495,7 +1495,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "uZ5KvBKwk9MU" + "id": "23a71e5f5227" }, "outputs": [], "source": [ @@ -1520,7 +1520,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "n5WXtatTwq2E" + "id": "367f598029e7" }, "source": [ "You could also chose not to compute a loss for certain outputs, if these outputs meant\n", @@ -1532,7 +1532,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "cw9oeLVlZqsj" + "id": "6d51aa372ef4" }, "outputs": [], "source": [ @@ -1553,7 +1553,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "pRqsnORfLIft" + "id": "8314a8b3a7c7" }, "source": [ "Passing data to a multi-input or multi-output model in fit works in a similar way as\n", @@ -1567,7 +1567,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "d9mSB81gVNzc" + "id": "0539da84328b" }, "outputs": [], "source": [ @@ -1598,7 +1598,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "GRy1WiDc4YVl" + "id": "e53eda8e1399" }, "source": [ "Here's the `Dataset` use case: similarly as what we did for NumPy arrays, the `Dataset`\n", @@ -1610,7 +1610,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "RTcpwknbR4Cs" + "id": "4df41a12ed2c" }, "outputs": [], "source": [ @@ -1629,7 +1629,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "iI5H2HQ9kOAr" + "id": "38ebf30ce6ac" }, "source": [ "## Using callbacks\n", @@ -1656,7 +1656,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "JW1vXhElEGl2" + "id": "15036ddbee42" }, "outputs": [], "source": [ @@ -1687,7 +1687,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "HS9QjLwuxbr9" + "id": "303815509732" }, "source": [ "### Many built-in callbacks are available\n", @@ -1720,7 +1720,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "eYTtAfg9mfBu" + "id": "b265d36ce608" }, "outputs": [], "source": [ @@ -1736,7 +1736,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "L1RfYWYuZJGV" + "id": "5ee672524987" }, "source": [ "## Checkpointing models\n", @@ -1752,7 +1752,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "nZDOgCGzvlzo" + "id": "83614be57725" }, "outputs": [], "source": [ @@ -1780,7 +1780,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "8T5ecYEa5lcq" + "id": "7f6afa36950c" }, "source": [ "The `ModelCheckpoint` callback can be used to implement fault-tolerance:\n", @@ -1793,7 +1793,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "i3mWcaFKsvOM" + "id": "27ce92b2ad58" }, "outputs": [], "source": [ @@ -1832,7 +1832,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "LNI3mjlibg0p" + "id": "da3ab58d5235" }, "source": [ "You call also write your own callback for saving and restoring models.\n", @@ -1845,7 +1845,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "kgGN7FXf8o5p" + "id": "b9342cc2ddba" }, "source": [ "## Using learning rate schedules\n", @@ -1868,7 +1868,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "kAe1QTyymmYj" + "id": "684f0ab6d3de" }, "outputs": [], "source": [ @@ -1884,7 +1884,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "u7UaKXWTlOx7" + "id": "7d742e44f535" }, "source": [ "Several built-in schedules are available: `ExponentialDecay`, `PiecewiseConstantDecay`,\n", @@ -1905,7 +1905,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "m1rNykV53SMA" + "id": "b4a05f880175" }, "source": [ "## Visualizing loss and metrics during training\n", @@ -1931,7 +1931,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "HA0zgb4rsJSg" + "id": "1fcf386a1dad" }, "source": [ "### Using the TensorBoard callback\n", @@ -1948,7 +1948,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "iVW4EVNAOtu2" + "id": "f74247282ff6" }, "outputs": [], "source": [ @@ -1964,7 +1964,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "i1gbeymgYVfd" + "id": "50cd5f8631fd" }, "source": [ "For more information, see the\n", diff --git a/tf/training_keras_models_on_cloud.ipynb b/tf/training_keras_models_on_cloud.ipynb index 9e98083eda..e54f24cde5 100644 --- a/tf/training_keras_models_on_cloud.ipynb +++ b/tf/training_keras_models_on_cloud.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "yYHVjlVnb3bO" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "t9nlPj2Gkc8u" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,7 +38,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "mJ8nm5R7CqPF" + "id": "c359f002e834" }, "source": [ "# Training Keras models with TensorFlow Cloud" @@ -48,7 +48,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "sp2wLtiqmLSJ" + "id": "f5c893a15fac" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "WbjNxTLmvEBa" + "id": "b1c0246f8536" }, "source": [ "## Introduction\n", @@ -91,7 +91,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "yiqN8MXkvOsb" + "id": "e015c75faba2" }, "source": [ "## Setup\n", @@ -105,7 +105,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "65s3ohBwwaHt" + "id": "99e5bc5e0ab8" }, "outputs": [], "source": [ @@ -117,7 +117,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "DNSIPzvqICMP" + "id": "26113effabca" }, "outputs": [], "source": [ @@ -132,7 +132,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "IaGy04c8qIZK" + "id": "e8568395c87b" }, "source": [ "## API overview: a first end-to-end example\n", @@ -175,7 +175,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "vBwNfWdb9cnG" + "id": "514f51a9a45d" }, "source": [ "To train this model on Google Cloud we just need to add a call to `run()` at\n", @@ -189,7 +189,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "C7D1uO2KSqR6" + "id": "6e38288bb617" }, "source": [ "You don't need to worry about cloud-specific tasks such as creating VM instances\n", @@ -212,7 +212,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "OyaL7br8kpA4" + "id": "3ab860e037c9" }, "source": [ "## Google Cloud configuration\n", @@ -248,7 +248,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "3nPK2VtcRJ07" + "id": "af5077731187" }, "outputs": [], "source": [ @@ -281,7 +281,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "E2FbrA3fbxvK" + "id": "5f2e65d8f3a6" }, "source": [ "Let's save the TensorBoard logs and model checkpoints generated during training\n", @@ -293,7 +293,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "xYiUspf7wwdP" + "id": "fdc4f951281c" }, "outputs": [], "source": [ @@ -325,7 +325,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "e7Es5zU7QNg1" + "id": "45d6210176e6" }, "source": [ "Here, we will load our data from Keras directly. In general, it's best practice\n", @@ -339,7 +339,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "eMuiImuPmCmZ" + "id": "bd4ef6ffa611" }, "outputs": [], "source": [ @@ -350,7 +350,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "ufV5UaOLlYOe" + "id": "b1d2a2688887" }, "source": [ "The [TensorFlow Cloud](https://github.com/tensorflow/cloud) API provides the\n", @@ -365,7 +365,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "i063cOBeK9jm" + "id": "cfab9ff41fd5" }, "outputs": [], "source": [ @@ -385,7 +385,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "sBqXbjlRsTie" + "id": "9b27c0b3b7db" }, "source": [ "Let's save the model in GCS after the training is complete." @@ -396,7 +396,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "cRrMLtlDNfia" + "id": "b00451dcfeab" }, "outputs": [], "source": [ @@ -410,7 +410,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Y7uyO3zmg4dw" + "id": "0dceb5b7a173" }, "source": [ "We can also use this storage bucket for Docker image building, instead of your local\n", @@ -422,7 +422,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "PRYngPn4hnYV" + "id": "13200523ed93" }, "outputs": [], "source": [ @@ -434,7 +434,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "RhO7K5JQ9ku6" + "id": "060a2112c34e" }, "source": [ "After training the model, we can load the saved model and view our TensorBoard logs\n", @@ -446,7 +446,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "QPaemWjpWk2w" + "id": "b8d773e2cfb7" }, "outputs": [], "source": [ @@ -459,7 +459,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "OC7TijaGfVpW" + "id": "05d1d68bae5a" }, "outputs": [], "source": [ @@ -471,7 +471,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "65CfJPGgnwlS" + "id": "3785ece03a8f" }, "source": [ "## Large-scale projects\n", @@ -535,7 +535,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "WiLCtjDsRg0J" + "id": "997e3f89c734" }, "source": [ "## Machine configuration and distributed training\n", @@ -570,7 +570,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "WrmpX0POFuC3" + "id": "e0d938efab72" }, "source": [ "### TPU distribution\n", @@ -589,7 +589,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "xJza2AOBGxFO" + "id": "d1dec83a0b19" }, "source": [ "### Custom distribution strategy\n", @@ -631,7 +631,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "7ujOoF14Fb6M" + "id": "0a50b62bf672" }, "source": [ "## Custom Docker images\n", @@ -653,7 +653,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "8qYHfcX1n8o0" + "id": "bb659015ffad" }, "source": [ "## Additional metrics\n", @@ -680,7 +680,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "P0biBY0zMB5o" + "id": "b34a2e8e09c3" }, "source": [ "## Putting it all together\n", diff --git a/tf/transfer_learning.ipynb b/tf/transfer_learning.ipynb index 2014bdc47c..dce7135913 100644 --- a/tf/transfer_learning.ipynb +++ b/tf/transfer_learning.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "wXqD7qkDQ8m5" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "h6ByrYO2iTdQ" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,17 +38,17 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "5xE2Li3CRtHl" + "id": "a81c428fc2d3" }, "source": [ - "# Transfer learning & fine-tuning" + "# Transfer learning and fine-tuning" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "BUgXiZUFNSnZ" + "id": "3e5a59f0aefd" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "XY1uY04Y63Ts" + "id": "8d4ac441b1fc" }, "source": [ "## Setup" @@ -82,7 +82,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "L24f6pm1DTaM" + "id": "9a7e9b92f963" }, "outputs": [], "source": [ @@ -95,7 +95,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "4hccQPeQLfSK" + "id": "00d4c41cfe2f" }, "source": [ "## Introduction\n", @@ -141,7 +141,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Mc9AB1fm1WC0" + "id": "fbf8630c325b" }, "source": [ "## Freezing layers: understanding the `trainable` attribute\n", @@ -162,7 +162,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "qfZqkMWfT7Fe" + "id": "407deab1855e" }, "outputs": [], "source": [ @@ -178,7 +178,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "P64dJdnOuZ7z" + "id": "79fcb9cc960d" }, "source": [ "In general, all weights are trainable weights. The only built-in layer that has\n", @@ -196,7 +196,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "tgxCoML9R3W5" + "id": "fbc87a09bc3c" }, "outputs": [], "source": [ @@ -212,7 +212,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "3KEGtVpIMbFz" + "id": "cddcdbf2bd5b" }, "source": [ "Layers & models also feature a boolean attribute `trainable`. Its value can be changed.\n", @@ -229,7 +229,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Jr689IGSD7Dk" + "id": "51bbc5d12742" }, "outputs": [], "source": [ @@ -246,7 +246,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "fp114z0z1MWX" + "id": "32904f9a58db" }, "source": [ "When a trainable weight becomes non-trainable, its value is no longer updated during\n", @@ -258,7 +258,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "h3oQ5uMxrQs8" + "id": "3c26c27a8291" }, "outputs": [], "source": [ @@ -291,7 +291,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "K6zbvhRDclvj" + "id": "412d7d659aa1" }, "source": [ "Do not confuse the `layer.trainable` attribute with the argument `training` in\n", @@ -305,7 +305,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "S9iYosPSu8cH" + "id": "e6ccd3c7ab1a" }, "source": [ "## Recursive setting of the `trainable` attribute\n", @@ -321,7 +321,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "g6jm5gxkj3SG" + "id": "4235d0c69821" }, "outputs": [], "source": [ @@ -347,7 +347,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "38hWFXGq4xuS" + "id": "61535ba76727" }, "source": [ "## The typical transfer-learning workflow\n", @@ -423,7 +423,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Nf7MojEtvlQb" + "id": "736c99aea690" }, "source": [ "## Fine-tuning\n", @@ -500,7 +500,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "XFN0ssHn5dXl" + "id": "bce9ffc4e290" }, "source": [ "## Transfer learning & fine-tuning with a custom training loop\n", @@ -548,7 +548,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "OlxpuOm98d73" + "id": "4e63ba34ce1c" }, "source": [ "Likewise for fine-tuning." @@ -558,7 +558,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "JEohy1c2leck" + "id": "ef30519fc7b6" }, "source": [ "## An end-to-end example: fine-tuning an image classification model on a cats vs. dogs\n", @@ -573,7 +573,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "I2n6GtEjwbZl" + "id": "ba75835e0de6" }, "source": [ "### Getting the data\n", @@ -593,7 +593,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "oJlf8c6e6HgE" + "id": "1a99f56934f7" }, "outputs": [], "source": [ @@ -619,7 +619,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "0J9WKmQJ8Ait" + "id": "9db548603642" }, "source": [ "These are the first 9 images in the training dataset -- as you can see, they're all\n", @@ -631,7 +631,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "pgXPig9MpSkk" + "id": "00c8cbd1de88" }, "outputs": [], "source": [ @@ -649,7 +649,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "s0rA5kGw6jS9" + "id": "168c4a10c072" }, "source": [ "We can also see that label 1 is \"dog\" and label 0 is \"cat\"." @@ -659,7 +659,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "CJpFXULV2hIz" + "id": "f749203cd740" }, "source": [ "### Standardizing the data\n", @@ -691,7 +691,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "aiztNjmfIEFP" + "id": "b3678f38e087" }, "outputs": [], "source": [ @@ -706,7 +706,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "a1v85QTCJsg6" + "id": "708bf9792a35" }, "source": [ "Besides, let's batch the data and use caching & prefetching to optimize loading speed." @@ -717,7 +717,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "yid9oKz1mjmR" + "id": "53ef9e6092e3" }, "outputs": [], "source": [ @@ -732,7 +732,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "LBIT1NSkCCVM" + "id": "b60f852c462f" }, "source": [ "### Using random data augmentation\n", @@ -749,7 +749,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "fwKfCmFlO44i" + "id": "40b1e355b9c0" }, "outputs": [], "source": [ @@ -768,7 +768,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "sQyBRpWd2wBO" + "id": "6fa8ddeda36e" }, "source": [ "Let's visualize what the first image of the first batch looks like after various random\n", @@ -780,7 +780,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "stqXtGQQNYSk" + "id": "e441d27e0783" }, "outputs": [], "source": [ @@ -803,7 +803,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "aMbavbXZxUFV" + "id": "bc999e4672c3" }, "source": [ "## Build a model\n", @@ -825,7 +825,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "1MCFad7DXUhV" + "id": "07a2f9e9d817" }, "outputs": [], "source": [ @@ -868,7 +868,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "wNBCrcy7mOyj" + "id": "2e8237de81e8" }, "source": [ "## Train the top layer" @@ -879,7 +879,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "CRKCCQVmEEEP" + "id": "9137b8daedad" }, "outputs": [], "source": [ @@ -897,7 +897,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "uOxFd1tlifHt" + "id": "aa51d4562fa7" }, "source": [ "## Do a round of fine-tuning of the entire model\n", @@ -917,7 +917,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "zsU49v2gLjJ7" + "id": "3cc299505b72" }, "outputs": [], "source": [ @@ -943,7 +943,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "XrjSK4KpvR6F" + "id": "afa73d989302" }, "source": [ "After 10 epochs, fine-tuning gains us a nice improvement here." diff --git a/tf/writing_a_training_loop_from_scratch.ipynb b/tf/writing_a_training_loop_from_scratch.ipynb index bc3441b73b..1879b93c60 100644 --- a/tf/writing_a_training_loop_from_scratch.ipynb +++ b/tf/writing_a_training_loop_from_scratch.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "i5R7Gb120Ekx" + "id": "b518b04cbfe0" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." @@ -17,7 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "XPflk8Ey7e9D" + "id": "906e07f6e562" }, "outputs": [], "source": [ @@ -38,7 +38,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "0pA8D5OrHGIx" + "id": "daf323e33b84" }, "source": [ "# Writing a training loop from scratch" @@ -48,7 +48,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "l7oVQp2POvp8" + "id": "2440f6e0c5ef" }, "source": [ "\n", @@ -56,13 +56,13 @@ " View on TensorFlow.org\n", " \n", " \n", " \n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", - " Download notebook\n", + " Download notebook\n", "
" ] @@ -71,7 +71,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "jkWTZxIyysDm" + "id": "8d4ac441b1fc" }, "source": [ "## Setup" @@ -82,7 +82,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "TcNr4V6Z2eDw" + "id": "ae2407ad926f" }, "outputs": [], "source": [ @@ -96,7 +96,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "MvWJHarCmdOp" + "id": "0f5a253901f8" }, "source": [ "## Introduction\n", @@ -120,7 +120,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "Xd8GpFudzEiU" + "id": "f4f47351a3ec" }, "source": [ "## Using the `GradientTape`: a first end-to-end example\n", @@ -138,7 +138,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "9uXwjRTjgQKE" + "id": "aaa775ce7dab" }, "outputs": [], "source": [ @@ -153,7 +153,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "xnxsNbPmMvqr" + "id": "d8b02a5759cf" }, "source": [ "Let's train it using mini-batch gradient with a custom training loop.\n", @@ -166,7 +166,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "VmZj17qo05qZ" + "id": "a2d5132ba859" }, "outputs": [], "source": [ @@ -188,7 +188,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "KP7wZij8LJyh" + "id": "5c30285b1a2e" }, "source": [ "Here's our training loop:\n", @@ -208,7 +208,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "vH60dyqVSDTX" + "id": "6374be9e3d47" }, "outputs": [], "source": [ @@ -253,7 +253,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "JUriDlmmzLey" + "id": "d600076b7be0" }, "source": [ "## Low-level handling of metrics\n", @@ -278,7 +278,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "IpAbe0hltQSv" + "id": "93650a9bd6d6" }, "outputs": [], "source": [ @@ -317,7 +317,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "XYep4rMxu9D1" + "id": "9111a5cc87dc" }, "source": [ "Here's our training & evaluation loop:" @@ -328,7 +328,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "uIzUVMFmKOL6" + "id": "ed4cd29fe1af" }, "outputs": [], "source": [ @@ -380,7 +380,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "rdU2jDOB4itB" + "id": "940d8d9fae83" }, "source": [ "## Speeding-up your training step with `tf.function`\n", @@ -404,7 +404,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "SpPlBEHjXg9c" + "id": "fdacc2d48ade" }, "outputs": [], "source": [ @@ -423,7 +423,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "2yGMv9LPrvYl" + "id": "ab61b0bf3126" }, "source": [ "Let's do the same with the evaluation step:" @@ -434,7 +434,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Y7Elq9Kky2HQ" + "id": "da4828fd8ef7" }, "outputs": [], "source": [ @@ -448,7 +448,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "jb12E4zoBDOy" + "id": "d552377968f1" }, "source": [ "Now, let's re-run our training loop with this compiled training step:" @@ -459,7 +459,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "kG0YiXFj519D" + "id": "cd859dbef477" }, "outputs": [], "source": [ @@ -503,7 +503,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "LtECMpVqBAl8" + "id": "8977d77a8095" }, "source": [ "Much faster, isn't it?" @@ -513,7 +513,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "EfiB6akb2kBT" + "id": "b5b5a54d339a" }, "source": [ "## Low-level handling of losses tracked by the model\n", @@ -534,7 +534,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "FuaN95bX7txO" + "id": "4ec7c4b16596" }, "outputs": [], "source": [ @@ -548,7 +548,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "u8JIjdc6sWRo" + "id": "6b12260b8bf2" }, "source": [ "Let's build a really simple model that uses it:" @@ -559,7 +559,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "xWEGiFOAg2Pw" + "id": "57afe49e6b93" }, "outputs": [], "source": [ @@ -577,7 +577,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "7dDTCiM3ikkt" + "id": "aadb58115c13" }, "source": [ "Here's what our training step should look like now:" @@ -588,7 +588,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "Ht7Utep1WEhg" + "id": "cf674776a0d2" }, "outputs": [], "source": [ @@ -609,7 +609,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "g1HCZDicyRMP" + "id": "0af04732fe78" }, "source": [ "## Summary\n", @@ -625,7 +625,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "oo0K12W14lTB" + "id": "9fb325331a1e" }, "source": [ "## End-to-end example: a GAN training loop from scratch\n", @@ -666,7 +666,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "CtDX25Xojcan" + "id": "fabf9cef3400" }, "outputs": [], "source": [ @@ -689,7 +689,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "y01N2V7Ykamk" + "id": "73396eb6daf9" }, "source": [ "Then let's create a generator network,\n", @@ -702,7 +702,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "1D0KbjVFlyye" + "id": "821d203bfb3e" }, "outputs": [], "source": [ @@ -729,7 +729,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "MGbCyv5MNPme" + "id": "f0d6d54a78a0" }, "source": [ "Here's the key bit: the training loop. As you can see it is quite straightforward. The\n", @@ -741,7 +741,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "UwFhElNElUpn" + "id": "3a11c875142e" }, "outputs": [], "source": [ @@ -795,7 +795,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "TfCAGhKdDEVa" + "id": "fa6bd6292488" }, "source": [ "Let's train our GAN, by repeatedly calling `train_step` on batches of images.\n", @@ -809,7 +809,7 @@ "execution_count": 0, "metadata": { "colab_type": "code", - "id": "RF070l5Ik9xo" + "id": "b6a4e3d42262" }, "outputs": [], "source": [ @@ -856,7 +856,7 @@ "cell_type": "markdown", "metadata": { "colab_type": "text", - "id": "sc7B8XhzD40j" + "id": "a92959ac630b" }, "source": [ "That's it! You'll get nice-looking fake MNIST digits after just ~30s of training on the\n",