未验证 提交 eb6c0cbe 编写于 作者: A Amit Patankar 提交者: GitHub

Merge branch 'r1.9' into r1.9

{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "U9i2Dsh-ziXr"
},
"source": [
"# Eager Execution Tutorial: Importing Data\n",
"\n",
"This notebook demonstrates the use of the [`tf.data.Dataset` API](https://www.tensorflow.org/guide/datasets) to build pipelines to feed data to your program. It covers:\n",
"\n",
"* Creating a `Dataset`.\n",
"* Iteration over a `Dataset` with eager execution enabled.\n",
"\n",
"We recommend using the `Dataset`s API for building performant, complex input pipelines from simple, re-usable pieces that will feed your model's training or evaluation loops.\n",
"\n",
"If you're familiar with TensorFlow graphs, the API for constructing the `Dataset` object remains exactly the same when eager execution is enabled, but the process of iterating over elements of the dataset is slightly simpler.\n",
"You can use Python iteration over the `tf.data.Dataset` object and do not need to explicitly create an `tf.data.Iterator` object.\n",
"As a result, the discussion on iterators in the [TensorFlow Guide](https://www.tensorflow.org/guide/datasets) is not relevant when eager execution is enabled."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "z1JcS5iBXMRO"
},
"source": [
"# Setup: Enable eager execution\n"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"cellView": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
},
"colab_type": "code",
"id": "RlIWhyeLoYnG"
},
"outputs": [],
"source": [
"# Import TensorFlow.\n",
"import tensorflow as tf\n",
"\n",
"# Enable eager execution\n",
"tf.enable_eager_execution()"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "H9UySOPLXdaw"
},
"source": [
"# Step 1: Create a source `Dataset`\n",
"\n",
"Create a _source_ dataset using one of the factory functions like [`Dataset.from_tensors`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset#from_tensors), [`Dataset.from_tensor_slices`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset#from_tensor_slices) or using objects that read from files like [`TextLineDataset`](https://www.tensorflow.org/api_docs/python/tf/data/TextLineDataset) or [`TFRecordDataset`](https://www.tensorflow.org/api_docs/python/tf/data/TFRecordDataset). See the [TensorFlow Guide](https://www.tensorflow.org/guide/datasets#reading_input_data) for more information."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"cellView": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
},
"colab_type": "code",
"id": "WPTUfGq6kJ5w"
},
"outputs": [],
"source": [
"ds_tensors = tf.data.Dataset.from_tensor_slices([1, 2, 3, 4, 5, 6])\n",
"\n",
"# Create a CSV file\n",
"import tempfile\n",
"_, filename = tempfile.mkstemp()\n",
"with open(filename, 'w') as f:\n",
" f.write(\"\"\"Line 1\n",
"Line 2\n",
"Line 3\n",
" \"\"\")\n",
"ds_file = tf.data.TextLineDataset(filename)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "twBfWd5xyu_d"
},
"source": [
"# Step 2: Apply transformations\n",
"\n",
"Use the transformations functions like [`map`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset#map), [`batch`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset#batch), [`shuffle`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset#shuffle) etc. to apply transformations to the records of the dataset. See the [API documentation for `tf.data.Dataset`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset) for details."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"cellView": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
},
"colab_type": "code",
"id": "ngUe237Wt48W"
},
"outputs": [],
"source": [
"ds_tensors = ds_tensors.map(tf.square).shuffle(2).batch(2)\n",
"ds_file = ds_file.batch(2)"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "IDY4WsYRhP81"
},
"source": [
"# Step 3: Iterate\n",
"\n",
"When eager execution is enabled `Dataset` objects support iteration.\n",
"If you're familiar with the use of `Dataset`s in TensorFlow graphs, note that there is no need for calls to `Dataset.make_one_shot_iterator()` or `get_next()` calls."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
},
"base_uri": "https://localhost:8080/",
"height": 153
},
"colab_type": "code",
"executionInfo": {
"elapsed": 388,
"status": "ok",
"timestamp": 1525154629129,
"user": {
"displayName": "",
"photoUrl": "",
"userId": ""
},
"user_tz": 420
},
"id": "lCUWzso6mbqR",
"outputId": "8e4b0298-d27d-4ac7-e26a-ef94af0594ec"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Elements of ds_tensors:\n",
"tf.Tensor([1 9], shape=(2,), dtype=int32)\n",
"tf.Tensor([16 25], shape=(2,), dtype=int32)\n",
"tf.Tensor([ 4 36], shape=(2,), dtype=int32)\n",
"\n",
"Elements in ds_file:\n",
"tf.Tensor(['Line 1' 'Line 2'], shape=(2,), dtype=string)\n",
"tf.Tensor(['Line 3' ' '], shape=(2,), dtype=string)\n"
]
}
],
"source": [
"print('Elements of ds_tensors:')\n",
"for x in ds_tensors:\n",
" print(x)\n",
"\n",
"print('\\nElements in ds_file:')\n",
"for x in ds_file:\n",
" print(x)"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"default_view": {},
"name": "Eager Execution Tutorial: Importing Data",
"provenance": [],
"version": "0.3.2",
"views": {}
}
},
"nbformat": 4,
"nbformat_minor": 0
}
## Research and experimentation
Eager execution provides an imperative, define-by-run interface for advanced
operations. Write custom layers, forward passes, and training loops with auto
differentiation. Start with these notebooks, then read the
[eager execution guide](https://www.tensorflow.org/guide/eager).
1. [Eager execution basics](./eager_basics.ipynb)
2. [Automatic differentiation and gradient tapes](./automatic_differentiation.ipynb)
3. [Custom training: basics](./custom_training.ipynb)
4. [Custom layers](./custom_layers.ipynb)
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "automatic_differentiation.ipynb",
"version": "0.3.2",
"views": {},
"default_view": {},
"provenance": [],
"private_outputs": true,
"collapsed_sections": [],
"toc_visible": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"metadata": {
"id": "t09eeeR5prIJ",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"##### Copyright 2018 The TensorFlow Authors."
]
},
{
"metadata": {
"id": "GCCk8_dHpuNf",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
},
"cellView": "form"
},
"cell_type": "code",
"source": [
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"#\n",
"# https://www.apache.org/licenses/LICENSE-2.0\n",
"#\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "xh8WkEwWpnm7",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"# Automatic differentiation and gradient tape"
]
},
{
"metadata": {
"id": "idv0bPeCp325",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"<table class=\"tfo-notebook-buttons\" align=\"left\"><td>\n",
"<a target=\"_blank\" href=\"https://colab.sandbox.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/notebooks/automatic_differentiation.ipynb\">\n",
" <img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /><span>Run in Google Colab</span></a>\n",
"</td><td>\n",
"<a target=\"_blank\" href=\"https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/notebooks/automatic_differentiation.ipynb\"><img width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /><span>View source on GitHub</span></a></td></table>"
]
},
{
"metadata": {
"id": "vDJ4XzMqodTy",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"In the previous tutorial we introduced `Tensor`s and operations on them. In this tutorial we will cover [automatic differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation), a key technique for optimizing machine learning models."
]
},
{
"metadata": {
"id": "GQJysDM__Qb0",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"## Setup\n"
]
},
{
"metadata": {
"id": "OiMPZStlibBv",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"import tensorflow as tf\n",
"tf.enable_eager_execution()\n",
"\n",
"tfe = tf.contrib.eager # Shorthand for some symbols"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "1CLWJl0QliB0",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"## Derivatives of a function\n",
"\n",
"TensorFlow provides APIs for automatic differentiation - computing the derivative of a function. The way that more closely mimics the math is to encapsulate the computation in a Python function, say `f`, and use `tfe.gradients_function` to create a function that computes the derivatives of `f` with respect to its arguments. If you're familiar with [autograd](https://github.com/HIPS/autograd) for differentiating numpy functions, this will be familiar. For example: "
]
},
{
"metadata": {
"id": "9FViq92UX7P8",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"from math import pi\n",
"\n",
"def f(x):\n",
" return tf.square(tf.sin(x))\n",
"\n",
"assert f(pi/2).numpy() == 1.0\n",
"\n",
"\n",
"# grad_f will return a list of derivatives of f\n",
"# with respect to its arguments. Since f() has a single argument,\n",
"# grad_f will return a list with a single element.\n",
"grad_f = tfe.gradients_function(f)\n",
"assert tf.abs(grad_f(pi/2)[0]).numpy() < 1e-7"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "v9fPs8RyopCf",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### Higher-order gradients\n",
"\n",
"The same API can be used to differentiate as many times as you like:\n"
]
},
{
"metadata": {
"id": "3D0ZvnGYo0rW",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"def f(x):\n",
" return tf.square(tf.sin(x))\n",
"\n",
"def grad(f):\n",
" return lambda x: tfe.gradients_function(f)(x)[0]\n",
"\n",
"x = tf.lin_space(-2*pi, 2*pi, 100) # 100 points between -2π and +2π\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.plot(x, f(x), label=\"f\")\n",
"plt.plot(x, grad(f)(x), label=\"first derivative\")\n",
"plt.plot(x, grad(grad(f))(x), label=\"second derivative\")\n",
"plt.plot(x, grad(grad(grad(f)))(x), label=\"third derivative\")\n",
"plt.legend()\n",
"plt.show()"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "-39gouo7mtgu",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"## Gradient tapes\n",
"\n",
"Every differentiable TensorFlow operation has an associated gradient function. For example, the gradient function of `tf.square(x)` would be a function that returns `2.0 * x`. To compute the gradient of a user-defined function (like `f(x)` in the example above), TensorFlow first \"records\" all the operations applied to compute the output of the function. We call this record a \"tape\". It then uses that tape and the gradients functions associated with each primitive operation to compute the gradients of the user-defined function using [reverse mode differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation).\n",
"\n",
"Since operations are recorded as they are executed, Python control flow (using `if`s and `while`s for example) is naturally handled:\n",
"\n"
]
},
{
"metadata": {
"id": "MH0UfjympWf7",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"def f(x, y):\n",
" output = 1\n",
" for i in range(y):\n",
" output = tf.multiply(output, x)\n",
" return output\n",
"\n",
"def g(x, y):\n",
" # Return the gradient of `f` with respect to it's first parameter\n",
" return tfe.gradients_function(f)(x, y)[0]\n",
"\n",
"assert f(3.0, 2).numpy() == 9.0 # f(x, 2) is essentially x * x\n",
"assert g(3.0, 2).numpy() == 6.0 # And its gradient will be 2 * x\n",
"assert f(4.0, 3).numpy() == 64.0 # f(x, 3) is essentially x * x * x\n",
"assert g(4.0, 3).numpy() == 48.0 # And its gradient will be 3 * x * x"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "aNmR5-jhpX2t",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"At times it may be inconvenient to encapsulate computation of interest into a function. For example, if you want the gradient of the output with respect to intermediate values computed in the function. In such cases, the slightly more verbose but explicit [tf.GradientTape](https://www.tensorflow.org/api_docs/python/tf/GradientTape) context is useful. All computation inside the context of a `tf.GradientTape` is \"recorded\".\n",
"\n",
"For example:"
]
},
{
"metadata": {
"id": "bAFeIE8EuVIq",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"x = tf.ones((2, 2))\n",
" \n",
"# TODO(b/78880779): Remove the 'persistent=True' argument and use\n",
"# a single t.gradient() call when the bug is resolved.\n",
"with tf.GradientTape(persistent=True) as t:\n",
" # TODO(ashankar): Explain with \"watch\" argument better?\n",
" t.watch(x)\n",
" y = tf.reduce_sum(x)\n",
" z = tf.multiply(y, y)\n",
"\n",
"# Use the same tape to compute the derivative of z with respect to the\n",
"# intermediate value y.\n",
"dz_dy = t.gradient(z, y)\n",
"assert dz_dy.numpy() == 8.0\n",
"\n",
"# Derivative of z with respect to the original input tensor x\n",
"dz_dx = t.gradient(z, x)\n",
"for i in [0, 1]:\n",
" for j in [0, 1]:\n",
" assert dz_dx[i][j].numpy() == 8.0"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "DK05KXrAAld3",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### Higher-order gradients\n",
"\n",
"Operations inside of the `GradientTape` context manager are recorded for automatic differentiation. If gradients are computed in that context, then the gradient computation is recorded as well. As a result, the exact same API works for higher-order gradients as well. For example:"
]
},
{
"metadata": {
"id": "cPQgthZ7ugRJ",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"# TODO(ashankar): Should we use the persistent tape here instead? Follow up on Tom and Alex's discussion\n",
"\n",
"x = tf.constant(1.0) # Convert the Python 1.0 to a Tensor object\n",
"\n",
"with tf.GradientTape() as t:\n",
" with tf.GradientTape() as t2:\n",
" t2.watch(x)\n",
" y = x * x * x\n",
" # Compute the gradient inside the 't' context manager\n",
" # which means the gradient computation is differentiable as well.\n",
" dy_dx = t2.gradient(y, x)\n",
"d2y_dx2 = t.gradient(dy_dx, x)\n",
"\n",
"assert dy_dx.numpy() == 3.0\n",
"assert d2y_dx2.numpy() == 6.0"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "4U1KKzUpNl58",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"## Next Steps\n",
"\n",
"In this tutorial we covered gradient computation in TensorFlow. With that we have enough of the primitives required to build an train neural networks, which we will cover in the [next tutorial](https://github.com/tensorflow/models/tree/master/official/contrib/eager/python/examples/notebooks/3_neural_networks.ipynb)."
]
}
]
}
\ No newline at end of file
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Custom training: basics",
"version": "0.3.2",
"views": {},
"default_view": {},
"provenance": [],
"private_outputs": true,
"collapsed_sections": [],
"toc_visible": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"metadata": {
"id": "5rmpybwysXGV",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"##### Copyright 2018 The TensorFlow Authors."
]
},
{
"metadata": {
"id": "m8y3rGtQsYP2",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
},
"cellView": "form"
},
"cell_type": "code",
"source": [
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"#\n",
"# https://www.apache.org/licenses/LICENSE-2.0\n",
"#\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "hrXv0rU9sIma",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"# Custom training: basics"
]
},
{
"metadata": {
"id": "7S0BwJ_8sLu7",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"<table class=\"tfo-notebook-buttons\" align=\"left\"><td>\n",
"<a target=\"_blank\" href=\"https://colab.sandbox.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/notebooks/custom_training.ipynb\">\n",
" <img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /><span>Run in Google Colab</span></a>\n",
"</td><td>\n",
"<a target=\"_blank\" href=\"https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/notebooks/custom_training.ipynb\"><img width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /><span>View source on GitHub</span></a></td></table>"
]
},
{
"metadata": {
"id": "k2o3TTG4TFpt",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"In the previous tutorial we covered the TensorFlow APIs for automatic differentiation, a basic building block for machine learning.\n",
"In this tutorial we will use the TensorFlow primitives introduced in the prior tutorials to do some simple machine learning.\n",
"\n",
"TensorFlow also includes a higher-level neural networks API (`tf.keras`) which provides useful abstractions to reduce boilerplate. We strongly recommend those higher level APIs for people working with neural networks. However, in this short tutorial we cover neural network training from first principles to establish a strong foundation."
]
},
{
"metadata": {
"id": "3LXMVuV0VhDr",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"## Setup"
]
},
{
"metadata": {
"id": "PJ64L90aVir3",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"import tensorflow as tf\n",
"tfe = tf.contrib.eager # Shorthand for some symbols\n",
"\n",
"tf.enable_eager_execution()"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "eMAWbDJFVmMk",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"## Variables\n",
"\n",
"Tensors in TensorFlow are immutable stateless objects. Machine learning models, however, need to have changing state: as your model trains, the same code to compute predictions should behave differently over time (hopefully with a lower loss!). To represent this state which needs to change over the course of your computation, you can choose to rely on the fact that Python is a stateful programming language:\n"
]
},
{
"metadata": {
"id": "VkJwtLS_Jbn8",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"# Using python state\n",
"x = tf.zeros([10, 10])\n",
"x += 2 # This is equivalent to x = x + 2, which does not mutate the original\n",
" # value of x\n",
"print(x)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "wfneTXy7JcUz",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"TensorFlow, however, has stateful operations built in, and these are often more pleasant to use than low-level Python representations of your state. To represent weights in a model, for example, it's often convenient and efficient to use TensorFlow variables.\n",
"\n",
"A Variable is an object which stores a value and, when used in a TensorFlow computation, will implicitly read from this stored value. There are operations (`tf.assign_sub`, `tf.scatter_update`, etc) which manipulate the value stored in a TensorFlow variable."
]
},
{
"metadata": {
"id": "itxmrMil6DQi",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"v = tfe.Variable(1.0)\n",
"assert v.numpy() == 1.0\n",
"\n",
"# Re-assign the value\n",
"v.assign(3.0)\n",
"assert v.numpy() == 3.0\n",
"\n",
"# Use `v` in a TensorFlow operation like tf.square() and reassign\n",
"v.assign(tf.square(v))\n",
"assert v.numpy() == 9.0"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "-paSaeq1JzwC",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"Computations using Variables are automatically traced when computing gradients. For Variables representing embeddings TensorFlow will do sparse updates by default, which are more computation and memory efficient.\n",
"\n",
"Using Variables is also a way to quickly let a reader of your code know that this piece of state is mutable."
]
},
{
"metadata": {
"id": "BMiFcDzE7Qu3",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"## Example: Fitting a linear model\n",
"\n",
"Let's now put the few concepts we have so far ---`Tensor`, `GradientTape`, `Variable` --- to build and train a simple model. This typically involves a few steps:\n",
"\n",
"1. Define the model.\n",
"2. Define a loss function.\n",
"3. Obtain training data.\n",
"4. Run through the training data and use an \"optimizer\" to adjust the variables to fit the data.\n",
"\n",
"In this tutorial, we'll walk through a trivial example of a simple linear model: `f(x) = x * W + b`, which has two variables - `W` and `b`. Furthermore, we'll synthesize data such that a well trained model would have `W = 3.0` and `b = 2.0`."
]
},
{
"metadata": {
"id": "gFzH64Jn9PIm",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### Define the model\n",
"\n",
"Let's define a simple class to encapsulate the variables and the computation."
]
},
{
"metadata": {
"id": "_WRu7Pze7wk8",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"class Model(object):\n",
" def __init__(self):\n",
" # Initialize variable to (5.0, 0.0)\n",
" # In practice, these should be initialized to random values.\n",
" self.W = tfe.Variable(5.0)\n",
" self.b = tfe.Variable(0.0)\n",
" \n",
" def __call__(self, x):\n",
" return self.W * x + self.b\n",
" \n",
"model = Model()\n",
"\n",
"assert model(3.0).numpy() == 15.0"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "xa6j_yXa-j79",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### Define a loss function\n",
"\n",
"A loss function measures how well the output of a model for a given input matches the desired output. Let's use the standard L2 loss."
]
},
{
"metadata": {
"id": "Y0ysUFGY924U",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"def loss(predicted_y, desired_y):\n",
" return tf.reduce_mean(tf.square(predicted_y - desired_y))"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "qutT_fkl_CBc",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### Obtain training data\n",
"\n",
"Let's synthesize the training data with some noise."
]
},
{
"metadata": {
"id": "gxPTb-kt_N5m",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"TRUE_W = 3.0\n",
"TRUE_b = 2.0\n",
"NUM_EXAMPLES = 1000\n",
"\n",
"inputs = tf.random_normal(shape=[NUM_EXAMPLES])\n",
"noise = tf.random_normal(shape=[NUM_EXAMPLES])\n",
"outputs = inputs * TRUE_W + TRUE_b + noise"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "-50nq-wPBsAW",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"Before we train the model let's visualize where the model stands right now. We'll plot the model's predictions in red and the training data in blue."
]
},
{
"metadata": {
"id": "_eb83LtrB4nt",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"plt.scatter(inputs, outputs, c='b')\n",
"plt.scatter(inputs, model(inputs), c='r')\n",
"plt.show()\n",
"\n",
"print('Current loss: '),\n",
"print(loss(model(inputs), outputs).numpy())"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "sSDP-yeq_4jE",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### Define a training loop\n",
"\n",
"We now have our network and our training data. Let's train it, i.e., use the training data to update the model's variables (`W` and `b`) so that the loss goes down using [gradient descent](https://en.wikipedia.org/wiki/Gradient_descent). There are many variants of the gradient descent scheme that are captured in `tf.train.Optimizer` implementations. We'd highly recommend using those implementations, but in the spirit of building from first principles, in this particular example we will implement the basic math ourselves."
]
},
{
"metadata": {
"id": "MBIACgdnA55X",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"def train(model, inputs, outputs, learning_rate):\n",
" with tf.GradientTape() as t:\n",
" current_loss = loss(model(inputs), outputs)\n",
" dW, db = t.gradient(current_loss, [model.W, model.b])\n",
" model.W.assign_sub(learning_rate * dW)\n",
" model.b.assign_sub(learning_rate * db)"
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "RwWPaJryD2aN",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"Finally, let's repeatedly run through the training data and see how `W` and `b` evolve."
]
},
{
"metadata": {
"id": "XdfkR223D9dW",
"colab_type": "code",
"colab": {
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
},
"cell_type": "code",
"source": [
"model = Model()\n",
"\n",
"# Collect the history of W-values and b-values to plot later\n",
"Ws, bs = [], []\n",
"epochs = range(10)\n",
"for epoch in epochs:\n",
" Ws.append(model.W.numpy())\n",
" bs.append(model.b.numpy())\n",
" current_loss = loss(model(inputs), outputs)\n",
"\n",
" train(model, inputs, outputs, learning_rate=0.1)\n",
" print('Epoch %2d: W=%1.2f b=%1.2f, loss=%2.5f' %\n",
" (epoch, Ws[-1], bs[-1], current_loss))\n",
"\n",
"# Let's plot it all\n",
"plt.plot(epochs, Ws, 'r',\n",
" epochs, bs, 'b')\n",
"plt.plot([TRUE_W] * len(epochs), 'r--',\n",
" [TRUE_b] * len(epochs), 'b--')\n",
"plt.legend(['W', 'b', 'true W', 'true_b'])\n",
"plt.show()\n",
" "
],
"execution_count": 0,
"outputs": []
},
{
"metadata": {
"id": "vPnIVuaSJwWz",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"## Next Steps\n",
"\n",
"In this tutorial we covered `Variable`s and built and trained a simple linear model using the TensorFlow primitives discussed so far.\n",
"\n",
"In theory, this is pretty much all you need to use TensorFlow for your machine learning research.\n",
"In practice, particularly for neural networks, the higher level APIs like `tf.keras` will be much more convenient since it provides higher level building blocks (called \"layers\"), utilities to save and restore state, a suite of loss functions, a suite of optimization strategies etc. \n",
"\n",
"The [next tutorial](TODO) will cover these higher level APIs."
]
}
]
}
\ No newline at end of file
......@@ -24,7 +24,7 @@ limitations under the License.
// TF_VERSION_SUFFIX is non-empty for pre-releases (e.g. "-alpha", "-alpha.1",
// "-beta", "-rc", "-rc.1")
#define TF_VERSION_SUFFIX "-rc2"
#define TF_VERSION_SUFFIX ""
#define TF_STR_HELPER(x) #x
#define TF_STR(x) TF_STR_HELPER(x)
......
......@@ -6,4 +6,3 @@ groups.md
documentation.md
style_guide.md
benchmarks.md
swift.md
<p align="center">
<img src="../images/swift_tensorflow_logo.png">
</p>
# Swift for TensorFlow
Welcome to the Swift for TensorFlow development community!
Swift for TensorFlow is a new way to develop machine learning models. It
gives you the power of
[TensorFlow](https://www.tensorflow.org) directly
integrated into the [Swift programming language](https://swift.org/about).
With Swift, you can write the following imperative code, and Swift
automatically turns it into **a single TensorFlow Graph** and runs it
with the full performance of TensorFlow Sessions on CPU, GPU and
[TPU](https://cloud.google.com/tpu/docs/tpus).
```swift
import TensorFlow
var x = Tensor<Float>([[1, 2], [3, 4]])
for i in 1...5 {
x += x x
}
print(x)
```
Swift combines the flexibility of
[Eager Execution](https://www.tensorflow.org/programmers_guide/eager) with the
high performance of [Graphs and Sessions](https://www.tensorflow.org/programmers_guide/graphs).
Behind the scenes, Swift analyzes your Tensor code and automatically builds
graphs for you. Swift also catches type errors and shape mismatches before
running your code, and has [Automatic Differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation)
built right in. We believe that machine learning tools are so important that
they deserve **a first-class language and a compiler**.
Note: Swift for TensorFlow is an early stage research project. It has been
released to enable open source development and is not yet ready for general use
by machine learning developers.
## Open Source
We have released Swift for TensorFlow as an open-source project on GitHub!
Our [documentation repository](https://github.com/tensorflow/swift) contains a
[project overview](https://github.com/tensorflow/swift/blob/master/docs/DesignOverview.md)
and [technical papers](https://github.com/tensorflow/swift/tree/master/docs)
explaining specific areas in depth. There are also instructions for [installing
pre-built packages](https://github.com/tensorflow/swift/blob/master/Installation.md)
(for macOS and Ubuntu) as well as a simple
[usage tutorial](https://github.com/tensorflow/swift/blob/master/Usage.md).
Moving forward, we will use an open design model and all discussions will be
public.
[Sign up here to join the community Google
group](https://groups.google.com/a/tensorflow.org/d/forum/swift), which we will
use for announcements and general discussion.
### Learn and use ML
basic_classification.md: Basic classification
basic_text_classification.md: Text classification
basic_regression.md: Regression
overfit_and_underfit.md
save_and_restore_models.md
next_steps.md
### Research and experimentation
eager.md
......@@ -362,10 +362,10 @@ model's loss. This is the
that will be optimized.
We can calculate the loss by calling @{tf.losses.sparse_softmax_cross_entropy}.
The value returned by this function will be lowest, approximately 0,
probability of the correct class (at index `label`) is near 1.0. The loss value
returned is progressively larger as the probability of the correct class
decreases.
The value returned by this function will be approximately 0 at lowest,
when the probability of the correct class (at index `label`) is near 1.0.
The loss value returned is progressively larger as the probability of the
correct class decreases.
This function returns the average over the whole batch.
......
......@@ -76,9 +76,9 @@ Let's walk through the `train_input_fn()`.
The function starts by using the @{tf.data.Dataset.from_tensor_slices} function
to create a @{tf.data.Dataset} representing slices of the array. The array is
sliced across the first dimension. For example, an array containing the
@{$tutorials/layers$mnist training data} has a shape of `(60000, 28, 28)`.
Passing this to `from_tensor_slices` returns a `Dataset` object containing
60000 slices, each one a 28x28 image.
MNIST training data has a shape of `(60000, 28, 28)`. Passing this to
`from_tensor_slices` returns a `Dataset` object containing 60000 slices, each one
a 28x28 image.
The code that returns this `Dataset` is as follows:
......
......@@ -17,7 +17,7 @@ how to use the graphical user interface (GUI) of tfdbg, i.e., the
Note: The TensorFlow debugger uses a
[curses](https://en.wikipedia.org/wiki/Curses_\(programming_library\))-based text
user interface. On Mac OS X, the `ncurses` library is required and can be
installed with `brew install homebrew/dupes/ncurses`. On Windows, curses isn't as
installed with `brew install ncurses`. On Windows, curses isn't as
well supported, so a [readline](https://en.wikipedia.org/wiki/GNU_Readline)-based
interface can be used with tfdbg by installing `pyreadline` with `pip`. If you
use Anaconda3, you can install it with a command such as
......@@ -33,8 +33,9 @@ and [`inf`s](https://en.wikipedia.org/wiki/Infinity), a frequently-encountered
type of bug in TensorFlow model development.
The following example is for users who use the low-level
[`Session`](https://www.tensorflow.org/api_docs/python/tf/Session) API of
TensorFlow. A later section of this document describes how to use **tfdbg**
with a higher-level API, namely `Estimator`s.
TensorFlow. Later sections of this document describe how to use **tfdbg**
with higher-level APIs of TensorFlow, including `tf.estimator`,
`tf.keras` / `keras` and `tf.contrib.slim`.
To *observe* such an issue, run the following command without the debugger (the
source code can be found
[here](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/debug/examples/debug_mnist.py)):
......@@ -209,6 +210,7 @@ Try the following commands at the `tfdbg>` prompt (referencing the code at
| **`config`** | | **Set or show persistent TFDBG UI configuration.** | |
| | `set` | Set the value of a config item: {`graph_recursion_depth`, `mouse_mode`}. | `config set graph_recursion_depth 3` |
| | `show` | Show current persistent UI configuration. | `config show` |
| **`version`** | | **Print the version of TensorFlow and its key dependencies.** | `version` |
| **`help`** | | **Print general help information** | `help` |
| | `help <command>` | Print help for given command. | `help lt` |
......@@ -461,7 +463,6 @@ predict_results = classifier.predict(predict_input_fn, hooks=hooks)
```
[debug_tflearn_iris.py](https://www.tensorflow.org/code/tensorflow/python/debug/examples/debug_tflearn_iris.py),
based on [tf-learn's iris tutorial](https://www.tensorflow.org/versions/r1.8/get_started/tflearn),
contains a full example of how to use the tfdbg with `Estimator`s.
To run this example, do:
......@@ -477,20 +478,31 @@ for more details.
## Debugging Keras Models with TFDBG
To use TFDBG with [Keras](https://keras.io/), let the Keras backend use
a TFDBG-wrapped Session object. For example, to use the CLI wrapper:
To use TFDBG with
[tf.keras](https://www.tensorflow.org/api_docs/python/tf/keras),
let the Keras backend use a TFDBG-wrapped Session object. For example, to use
the CLI wrapper:
``` python
import tensorflow as tf
from keras import backend as keras_backend
from tensorflow.python import debug as tf_debug
keras_backend.set_session(tf_debug.LocalCLIDebugWrapperSession(tf.Session()))
tf.keras.backend.set_session(tf_debug.LocalCLIDebugWrapperSession(tf.Session()))
# Define your keras model, called "model".
model.fit(...) # This will break into the TFDBG CLI.
# Calls to `fit()`, 'evaluate()` and `predict()` methods will break into the
# TFDBG CLI.
model.fit(...)
model.evaluate(...)
model.predict(...)
```
With minor modification, the preceding code example also works for the
[non-TensorFlow version of Keras](https://keras.io/) running against a
TensorFlow backend. You just need to replace `tf.keras.backend` with
`keras.backend`.
## Debugging tf-slim with TFDBG
TFDBG supports debugging of training and evaluation with
......
......@@ -149,16 +149,17 @@ it to implement your own layer:
```py
class MySimpleLayer(tf.keras.layers.Layer):
def __init__(self, output_units):
super(MySimpleLayer, self).__init__()
self.output_units = output_units
def build(self, input):
def build(self, input_shape):
# The build method gets called the first time your layer is used.
# Creating variables on build() allows you to make their shape depend
# on the input shape and hence remove the need for the user to specify
# on the input shape and hence removes the need for the user to specify
# full shapes. It is possible to create variables during __init__() if
# you already know their full shapes.
self.kernel = self.add_variable(
"kernel", [input.shape[-1], self.output_units])
"kernel", [input_shape[-1], self.output_units])
def call(self, input):
# Override call() instead of __call__ so we can perform some bookkeeping.
......@@ -315,9 +316,8 @@ for (batch, (images, labels)) in enumerate(dataset):
The following example creates a multi-layer model that classifies the standard
[MNIST handwritten digits](https://www.tensorflow.org/tutorials/layers). It
demonstrates the optimizer and layer APIs to build trainable graphs in an eager
execution environment.
MNIST handwritten digits. It demonstrates the optimizer and layer APIs to build
trainable graphs in an eager execution environment.
### Train a model
......
......@@ -486,7 +486,7 @@ subgraph inside.
![](../images/mnist_deep.png)
For more information about visualizing your TensorFlow application with
TensorBoard, see the [TensorBoard tutorial](../get_started/summaries_and_tensorboard.md).
TensorBoard, see the [TensorBoard guide](./summaries_and_tensorboard.md).
## Programming with multiple graphs
......
......@@ -221,7 +221,7 @@ To *evaluate* the inference-mode loss and metrics for the data provided:
```python
model.evaluate(x, y, batch_size=32)
model.evaluate(dataset, steps=30
model.evaluate(dataset, steps=30)
```
And to *predict* the output of the last layer in inference for the data provided,
......@@ -548,11 +548,9 @@ model.compile(optimizer=tf.train.RMSPropOptimizer(0.001),
estimator = keras.estimator.model_to_estimator(model)
```
Note:
* Enable [eager execution](./eager.md) for debugging
Note: Enable [eager execution](./eager.md) for debugging
[Estimator input functions](./premade_estimators.md#create_input_functions)
and inspecting data.
* Don't use batch normalization or try to finetune batch normalization models with estimators created from `tf.keras.estimator.model_to_estimator`. More details at [#17950](https://github.com/tensorflow/tensorflow/issues/17950)
### Multiple GPUs
......@@ -583,15 +581,6 @@ model.compile(loss='binary_crossentropy', optimizer=optimizer)
model.summary()
```
Convert the Keras model to a `tf.estimator.Estimator` instance:
```python
keras_estimator = keras.estimator.model_to_estimator(
keras_model=model,
config=config,
model_dir='/tmp/model_dir')
```
Define an *input pipeline*. The `input_fn` returns a `tf.data.Dataset` object
used to distribute the data across multiple devices—with each device processing
a slice of the input batch.
......@@ -617,6 +606,15 @@ strategy = tf.contrib.distribute.MirroredStrategy()
config = tf.estimator.RunConfig(train_distribute=strategy)
```
Convert the Keras model to a `tf.estimator.Estimator` instance:
```python
keras_estimator = keras.estimator.model_to_estimator(
keras_model=model,
config=config,
model_dir='/tmp/model_dir')
```
Finally, train the `Estimator` instance by providing the `input_fn` and `steps`
arguments:
......
......@@ -794,11 +794,12 @@ Here's the syntax:
```
usage: saved_model_cli run [-h] --dir DIR --tag_set TAG_SET --signature_def
SIGNATURE_DEF_KEY [--inputs INPUTS]
[--input_exprs INPUT_EXPRS] [--outdir OUTDIR]
[--input_exprs INPUT_EXPRS]
[--input_examples INPUT_EXAMPLES] [--outdir OUTDIR]
[--overwrite] [--tf_debug]
```
The `run` command provides the following two ways to pass inputs to the model:
The `run` command provides the following three ways to pass inputs to the model:
* `--inputs` option enables you to pass numpy ndarray in files.
* `--input_exprs` option enables you to pass Python expressions.
......@@ -847,7 +848,7 @@ dictionary is stored in the pickle file and the value corresponding to
the *variable_name* will be used.
#### `--inputs_exprs`
#### `--input_exprs`
To pass inputs through Python expressions, specify the `--input_exprs` option.
This can be useful for when you don't have data
......@@ -869,7 +870,7 @@ example:
(Note that the `numpy` module is already available to you as `np`.)
#### `--inputs_examples`
#### `--input_examples`
To pass `tf.train.Example` as inputs, specify the `--input_examples` option.
For each input key, it takes a list of dictionary, where each dictionary is an
......
......@@ -13,8 +13,8 @@ TensorFlow has an op
which is perfect for this purpose. As is usually the case with TensorBoard, we
will ingest data using a summary op; in this case,
['tf.summary.histogram'](https://www.tensorflow.org/api_docs/python/tf/summary/histogram).
For a primer on how summaries work, please see the general
[TensorBoard tutorial](https://www.tensorflow.org/get_started/summaries_and_tensorboard).
For a primer on how summaries work, please see the
[TensorBoard guide](./summaries_and_tensorboard.md).
Here is a code snippet that will generate some histogram summaries containing
normally distributed data, where the mean of the distribution increases over
......
......@@ -38,7 +38,7 @@ enable TensorFlow for C:
OS="linux" # Change to "darwin" for macOS
TARGET_DIRECTORY="/usr/local"
curl -L \
"https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-${OS}-x86_64-1.9.0-rc2.tar.gz" |
"https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-${OS}-x86_64-1.9.0.tar.gz" |
sudo tar -C $TARGET_DIRECTORY -xz
The `tar` command extracts the TensorFlow C library into the `lib`
......
......@@ -38,7 +38,7 @@ steps to install this library and enable TensorFlow for Go:
TF_TYPE="cpu" # Change to "gpu" for GPU support
TARGET_DIRECTORY='/usr/local'
curl -L \
"https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-$(go env GOOS)-x86_64-1.9.0-rc2.tar.gz" |
"https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-$(go env GOOS)-x86_64-1.9.0.tar.gz" |
sudo tar -C $TARGET_DIRECTORY -xz
The `tar` command extracts the TensorFlow C library into the `lib`
......
......@@ -36,7 +36,7 @@ following to the project's `pom.xml` to use the TensorFlow Java APIs:
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow</artifactId>
<version>1.9.0-rc2</version>
<version>1.9.0</version>
</dependency>
```
......@@ -65,7 +65,7 @@ As an example, these steps will create a Maven project that uses TensorFlow:
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow</artifactId>
<version>1.9.0-rc2</version>
<version>1.9.0</version>
</dependency>
</dependencies>
</project>
......@@ -124,12 +124,12 @@ instead:
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>libtensorflow</artifactId>
<version>1.9.0-rc2</version>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>libtensorflow_jni_gpu</artifactId>
<version>1.9.0-rc2</version>
<version>1.9.0</version>
</dependency>
```
......@@ -148,7 +148,7 @@ refer to the simpler instructions above instead.
Take the following steps to install TensorFlow for Java on Linux or macOS:
1. Download
[libtensorflow.jar](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-1.9.0-rc2.jar),
[libtensorflow.jar](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-1.9.0.jar),
which is the TensorFlow Java Archive (JAR).
2. Decide whether you will run TensorFlow for Java on CPU(s) only or with
......@@ -167,7 +167,7 @@ Take the following steps to install TensorFlow for Java on Linux or macOS:
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
mkdir -p ./jni
curl -L \
"https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-${TF_TYPE}-${OS}-x86_64-1.9.0-rc2.tar.gz" |
"https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-${TF_TYPE}-${OS}-x86_64-1.9.0.tar.gz" |
tar -xz -C ./jni
### Install on Windows
......@@ -175,13 +175,13 @@ Take the following steps to install TensorFlow for Java on Linux or macOS:
Take the following steps to install TensorFlow for Java on Windows:
1. Download
[libtensorflow.jar](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-1.9.0-rc2.jar),
[libtensorflow.jar](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-1.9.0.jar),
which is the TensorFlow Java Archive (JAR).
2. Download the following Java Native Interface (JNI) file appropriate for
[TensorFlow for Java on Windows](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-cpu-windows-x86_64-1.9.0-rc2.zip).
[TensorFlow for Java on Windows](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-cpu-windows-x86_64-1.9.0.zip).
3. Extract this .zip file.
__Note__: The native library (`tensorflow_jni.dll`) requires `msvcp140.dll` at runtime, which is included in the [Visual C++ 2015 Redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=48145) package.
### Validate the installation
......@@ -227,7 +227,7 @@ must be part of your `classpath`. For example, you can include the
downloaded `.jar` in your `classpath` by using the `-cp` compilation flag
as follows:
<pre><b>javac -cp libtensorflow-1.9.0-rc2.jar HelloTF.java</b></pre>
<pre><b>javac -cp libtensorflow-1.9.0.jar HelloTF.java</b></pre>
### Running
......@@ -241,11 +241,11 @@ two files are available to the JVM:
For example, the following command line executes the `HelloTF` program on Linux
and macOS X:
<pre><b>java -cp libtensorflow-1.9.0-rc2.jar:. -Djava.library.path=./jni HelloTF</b></pre>
<pre><b>java -cp libtensorflow-1.9.0.jar:. -Djava.library.path=./jni HelloTF</b></pre>
And the following command line executes the `HelloTF` program on Windows:
<pre><b>java -cp libtensorflow-1.9.0-rc2.jar;. -Djava.library.path=jni HelloTF</b></pre>
<pre><b>java -cp libtensorflow-1.9.0.jar;. -Djava.library.path=jni HelloTF</b></pre>
If the program prints <tt>Hello from <i>version</i></tt>, you've successfully
installed TensorFlow for Java and are ready to use the API. If the program
......
......@@ -339,9 +339,7 @@ Docker will download the TensorFlow binary image the first time you launch it.
#### GPU support
Prior to installing TensorFlow with GPU support, ensure that your system meets all
[NVIDIA software requirements](#NVIDIARequirements). To launch a Docker container
with NVidia GPU support, enter a command of the following format:
To launch a Docker container with NVidia GPU support, enter a command of the following format (this [does not require any local CUDA installation](https://github.com/nvidia/nvidia-docker/wiki/CUDA#requirements)):
<pre>
$ <b>nvidia-docker run -it</b> <i>-p hostPort:containerPort TensorFlowGPUImage</i>
......@@ -438,7 +436,7 @@ Take the following steps to install TensorFlow in an Anaconda environment:
<pre>
(tensorflow)$ <b>pip install --ignore-installed --upgrade \
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0rc2-cp34-cp34m-linux_x86_64.whl</b></pre>
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0-cp34-cp34m-linux_x86_64.whl</b></pre>
<a name="ValidateYourInstallation"></a>
## Validate your installation
......@@ -491,7 +489,7 @@ TensorFlow programs:
If the system outputs an error message instead of a greeting, see [Common
installation problems](#common_installation_problems).
To learn more, see [Get Started with TensorFlow](https://www.tensorflow.org/get_started).
To learn more, see the [TensorFlow tutorials](../tutorials/).
<a name="NVIDIARequirements"></a>
## TensorFlow GPU support
......@@ -678,14 +676,14 @@ This section documents the relevant values for Linux installations.
CPU only:
<pre>
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0rc2-cp27-none-linux_x86_64.whl
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0-cp27-none-linux_x86_64.whl
</pre>
GPU support:
<pre>
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.9.0rc2-cp27-none-linux_x86_64.whl
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.9.0-cp27-none-linux_x86_64.whl
</pre>
Note that GPU support requires the NVIDIA hardware and software described in
......@@ -697,14 +695,14 @@ Note that GPU support requires the NVIDIA hardware and software described in
CPU only:
<pre>
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0rc2-cp34-cp34m-linux_x86_64.whl
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0-cp34-cp34m-linux_x86_64.whl
</pre>
GPU support:
<pre>
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.9.0rc2-cp34-cp34m-linux_x86_64.whl
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.9.0-cp34-cp34m-linux_x86_64.whl
</pre>
Note that GPU support requires the NVIDIA hardware and software described in
......@@ -716,14 +714,14 @@ Note that GPU support requires the NVIDIA hardware and software described in
CPU only:
<pre>
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0rc2-cp35-cp35m-linux_x86_64.whl
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0-cp35-cp35m-linux_x86_64.whl
</pre>
GPU support:
<pre>
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.9.0rc2-cp35-cp35m-linux_x86_64.whl
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.9.0-cp35-cp35m-linux_x86_64.whl
</pre>
......@@ -735,14 +733,14 @@ Note that GPU support requires the NVIDIA hardware and software described in
CPU only:
<pre>
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0rc2-cp36-cp36m-linux_x86_64.whl
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0-cp36-cp36m-linux_x86_64.whl
</pre>
GPU support:
<pre>
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.9.0rc2-cp36-cp36m-linux_x86_64.whl
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.9.0-cp36-cp36m-linux_x86_64.whl
</pre>
......
......@@ -119,7 +119,7 @@ Take the following steps to install TensorFlow with Virtualenv:
TensorFlow in the active Virtualenv is as follows:
<pre> $ <b>pip3 install --upgrade \
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0rc2-py3-none-any.whl</b></pre>
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0-py3-none-any.whl</b></pre>
If you encounter installation problems, see
[Common Installation Problems](#common-installation-problems).
......@@ -242,7 +242,7 @@ take the following steps:
issue the following command:
<pre> $ <b>sudo pip3 install --upgrade \
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0rc2-py3-none-any.whl</b> </pre>
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0-py3-none-any.whl</b> </pre>
If the preceding command fails, see
[installation problems](#common-installation-problems).
......@@ -350,7 +350,7 @@ Take the following steps to install TensorFlow in an Anaconda environment:
TensorFlow for Python 2.7:
<pre> (<i>targetDirectory</i>)$ <b>pip install --ignore-installed --upgrade \
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0rc2-py2-none-any.whl</b></pre>
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0-py2-none-any.whl</b></pre>
<a name="ValidateYourInstallation"></a>
......@@ -403,8 +403,7 @@ writing TensorFlow programs:
If the system outputs an error message instead of a greeting, see
[Common installation problems](#common_installation_problems).
To learn more, see [Get Started with TensorFlow](https://www.tensorflow.org/get_started).
To learn more, see the [TensorFlow tutorials](../tutorials/).
## Common installation problems
......@@ -518,7 +517,7 @@ The value you specify depends on your Python version.
<pre>
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0rc2-py2-none-any.whl
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0-py2-none-any.whl
</pre>
......@@ -526,5 +525,5 @@ https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0rc2-py2-none-a
<pre>
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0rc2-py3-none-any.whl
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0-py3-none-any.whl
</pre>
......@@ -230,7 +230,7 @@ problems, despite the log message.
If the system outputs an error message instead of a greeting, see [Common
installation problems](#common_installation_problems).
To learn more, see [Get Started with TensorFlow](https://www.tensorflow.org/get_started).
To learn more, see the [TensorFlow tutorials](../tutorials/).
## Common installation problems
......
......@@ -81,7 +81,7 @@ or
[macOS](#PrepareMac)
<a name="#PrepareLinux"></a>
<a name="PrepareLinux"></a>
## Prepare environment for Linux
Before building TensorFlow on Linux, install the following build
......@@ -289,17 +289,27 @@ Note: If you're only interested in building the libraries for the TensorFlow C
or Java APIs, see [Build the C or Java libraries](#BuildCorJava), you do not
need to build the pip package in that case.
To build a pip package for TensorFlow with CPU-only support,
you would typically invoke the following command:
### CPU-only support
To build a pip package for TensorFlow with CPU-only support:
<pre>
$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
</pre>
To build a pip package for TensorFlow with CPU-only support for the Intel® MKL-DNN:
<pre>
$ <b>bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package</b>
$ bazel build --config=mkl --config=opt //tensorflow/tools/pip_package:build_pip_package
</pre>
To build a pip package for TensorFlow with GPU support,
invoke the following command:
### GPU support
To build a pip package for TensorFlow with GPU support:
<pre>$ <b>bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package</b> </pre>
<pre>
$ bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
</pre>
**NOTE on gcc 5 or later:** the binary pip packages available on the
TensorFlow website are built with gcc 4, which uses the older ABI. To
......@@ -328,10 +338,10 @@ Invoke `pip install` to install that pip package.
The filename of the `.whl` file depends on your platform.
For example, the following command will install the pip package
for TensorFlow 1.9.0rc2 on Linux:
for TensorFlow 1.9.0 on Linux:
<pre>
$ <b>sudo pip install /tmp/tensorflow_pkg/tensorflow-1.9.0rc2-py2-none-any.whl</b>
$ <b>sudo pip install /tmp/tensorflow_pkg/tensorflow-1.9.0-py2-none-any.whl</b>
</pre>
## Validate your installation
......@@ -362,7 +372,7 @@ TensorFlow programs:
<pre>Hello, TensorFlow!</pre>
To learn more, see [Get Started with TensorFlow](https://www.tensorflow.org/get_started).
To learn more, see the [TensorFlow tutorials](../tutorials/).
If the system outputs an error message instead of a greeting, see [Common
installation problems](#common_installation_problems).
......@@ -373,9 +383,9 @@ The build and installation problems you encounter typically depend on the
operating system. See the "Common installation problems" section
of one of the following guides:
* @{$install_linux#CommonInstallationProblems$Installing TensorFlow on Linux}
* @{$install_mac#CommonInstallationProblems$Installing TensorFlow on Mac OS}
* @{$install_windows#CommonInstallationProblems$Installing TensorFlow on Windows}
* @{$install_linux#common_installation_problems$Installing TensorFlow on Linux}
* @{$install_mac#common_installation_problems$Installing TensorFlow on Mac OS}
* @{$install_windows#common_installation_problems$Installing TensorFlow on Windows}
Beyond the errors documented in those two guides, the following table
notes additional errors specific to building TensorFlow. Note that we
......
......@@ -157,7 +157,7 @@ TensorFlow programs:
If the system outputs an error message instead of a greeting, see [Common
installation problems](#common_installation_problems).
To learn more, see [Get Started with TensorFlow](https://www.tensorflow.org/get_started).
To learn more, see the [TensorFlow tutorials](../tutorials/).
## Common installation problems
......
......@@ -4,6 +4,7 @@ tflite/index.md
tflite/devguide.md
tflite/demo_android.md
tflite/demo_ios.md
tflite/performance.md
>>>
### TensorFlow Mobile
mobile_intro.md
......
......@@ -27,7 +27,7 @@ called `libandroid_tensorflow_inference_java.jar`. There are three ways to
include this functionality in your program:
1. Include the jcenter AAR which contains it, as in this
[example app](https://github.com/googlecodelabs/tensorflow-for-poets-2/blob/master/android/build.gradle#L59-L65)
[example app](https://github.com/googlecodelabs/tensorflow-for-poets-2/blob/master/android/tfmobile/build.gradle#L59-L65)
2. Download the nightly precompiled version from
[ci.tensorflow.org](http://ci.tensorflow.org/view/Nightly/job/nightly-android/lastSuccessfulBuild/artifact/out/).
......
......@@ -38,7 +38,8 @@ speech-driven interface, and many of these require on-device processing. Most of
the time a user isn’t giving commands, and so streaming audio continuously to a
remote server would be a waste of bandwidth, since it would mostly be silence or
background noises. To solve this problem it’s common to have a small neural
network running on-device @{$tutorials/audio_recognition$listening out for a particular keyword}.
network running on-device
[listening out for a particular keyword](../tutorials/sequences/audio_recognition).
Once that keyword has been spotted, the rest of the
conversation can be transmitted over to the server for further processing if
more computing power is needed.
......
......@@ -105,8 +105,8 @@ inline constants so everything’s in one file. To handle the conversion, you
need the `freeze_graph.py` script, that’s held in
[`tensorflow/python/tools/freeze_graph.py`](https://www.tensorflow.org/code/tensorflow/python/tools/freeze_graph.py). You’ll run it like this:
bazel build tensorflow/tools:freeze_graph
bazel-bin/tensorflow/tools/freeze_graph \
bazel build tensorflow/python/tools:freeze_graph
bazel-bin/tensorflow/python/tools/freeze_graph \
--input_graph=/tmp/model/my_graph.pb \
--input_checkpoint=/tmp/model/model.ckpt-1000 \
--output_graph=/tmp/frozen_graph.pb \
......
# Android Demo App
An example Android application using TensorFLow Lite is available
[on GitHub](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite/java/demo/app).
[on GitHub](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite/java/demo).
The demo is a sample camera app that classifies images continuously
using either a quantized Mobilenet model or a floating point Inception-v3 model.
To run the demo, a device running Android 5.0 ( API 21) or higher is required.
......@@ -44,20 +44,22 @@ app:
Android Studio project.
* Install all the Gradle extensions it requests.
To get a model, either:
Now you can build and run the demo app.
* Download the quantized [Mobilenet TensorFlow Lite model](https://storage.googleapis.com/download.tensorflow.org/models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip)
and unzip and copy `mobilenet_quant_v1_224.tflite` to the assets directory:
`tensorflow/contrib/lite/java/demo/app/src/main/assets/`.
* Or, download the floating point [Inception-v3 model](https://storage.googleapis.com/download.tensorflow.org/models/tflite/inception_v3_slim_2016_android_2017_11_10.zip)
and unzip and copy `inceptionv3_non_slim_2015.tflite` to the assets
directory. Change the chosen classifier in
[Camera2BasicFragment.java](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/java/demo/app/src/main/java/com/example/android/tflitecamerademo/Camera2BasicFragment.java)<br>
The build process downloads the quantized [Mobilenet TensorFlow Lite model](https://storage.googleapis.com/download.tensorflow.org/models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip), and unzips it into the assets directory: `tensorflow/contrib/lite/java/demo/app/src/main/assets/`.
Some additional details are available on the
[TF Lite Android App page](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite/java/demo/README.md).
### Using other models
To use a different model:
* Download the floating point [Inception-v3 model](https://storage.googleapis.com/download.tensorflow.org/models/tflite/inception_v3_slim_2016_android_2017_11_10.zip).
* Unzip and copy `inceptionv3_non_slim_2015.tflite` to the assets directory.
* Change the chosen classifier in [Camera2BasicFragment.java](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/java/demo/app/src/main/java/com/example/android/tflitecamerademo/Camera2BasicFragment.java)<br>
from: `classifier = new ImageClassifierQuantizedMobileNet(getActivity());`<br>
to: `classifier = new ImageClassifierFloatInception(getActivity());`.
Now you can build and run the demo app.
## Build TensorFlow Lite and the demo app from source
......
......@@ -54,10 +54,11 @@ both floating point and quantized inference.
### Train a custom model
A developer may choose to train a custom model using Tensorflow (see the
@{$tutorials} for examples of building and training models). If you have already
written a model, the first step is to export this to a @{tf.GraphDef} file. This
is required because some formats do not store the model structure outside the
code, and we must communicate with other parts of the framework. See
[TensorFlow tutorials](../../tutorials/) for examples of building and training
models). If you have already written a model, the first step is to export this
to a @{tf.GraphDef} file. This is required because some formats do not store the
model structure outside the code, and we must communicate with other parts of the
framework. See
[Exporting the Inference Graph](https://github.com/tensorflow/models/blob/master/research/slim/README.md)
to create .pb file for the custom model.
......
......@@ -37,8 +37,9 @@ a custom (less-dynamic) memory allocator to ensure minimal load, initialization,
and execution latency.
TensorFlow Lite provides an interface to leverage hardware acceleration, if
available on the device. It does so via the Android Neural Networks library,
released as part of Android O-MR1.
available on the device. It does so via the
[Android Neural Networks API](https://developer.android.com/ndk/guides/neuralnetworks/index.html),
available on Android 8.1 (API level 27) and higher.
## Why do we need a new mobile-specific library?
......@@ -116,6 +117,10 @@ following:
Wear](https://research.googleblog.com/2017/02/on-device-machine-intelligence.html)
to all first-party and third-party apps.
Also see the complete list of
[TensorFlow Lite's supported models](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/g3doc/models.md),
including the model sizes, performance numbers, and downloadable model files.
- Quantized versions of the MobileNet model, which runs faster than the
non-quantized (float) version on CPU.
......@@ -131,10 +136,10 @@ compatibility with this release.
## Getting Started
We recommend you try out TensorFlow Lite with the pre-tested models indicated
above. If you have an existing mode, you will need to test whether your model is
compatible with both the converter and the supported operator set. To test your
model, see the [documentation on
GitHub](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite).
above. If you have an existing model, you will need to test whether your model
is compatible with both the converter and the supported operator set. To test
your model, see the
[documentation on GitHub](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite).
### Retrain Inception-V3 or MobileNet for a custom data set
......
此差异已折叠。
......@@ -227,8 +227,8 @@ of 30.0f, and an 8-bit array, the quantized values represent the following:
<table>
<tr><th>Quantized</th><th>Float</th></tr>
<tr><td>0</td><td>-10.0</td></tr>
<tr><td>255</td><td>30.0</td></tr>
<tr><td>128</td><td>10.0</td></tr>
<tr><td>255</td><td>30.0</td></tr>
</table>
<figcaption>
<b>Table 2</b>: Example quantized value range
......
......@@ -581,12 +581,21 @@ Computes a sum across replicas.
Arguments | Type | Semantics
--------- | ------- | -----------------------------
`operand` | `XlaOp` | Array to sum across replicas.
| `replica_group_ids` | `int64` vector | Group ID for each replica. |
The output shape is the same as the input shape. For example, if there are two
replicas and the operand has the value `(1.0, 2.5)` and `(3.0, 5.25)`
respectively on the two replicas, then the output value from this op will be
`(4.0, 7.75)` on both replicas.
`replica_group_ids` identifies the group ID of each replica. The group ID must
either be empty (all replicas belong to a single group), or contain the same
number of elements as the number of replicas. For example, if
`replica_group_ids` = {0, 1, 2, 3, 0, 1, 2, 3} has eight replicas, there are
four subgroups of replica IDs: {0, 4}, {1, 5}, {2, 6}, and {3, 7}. The size of
each subgroup *must* be identical, so, for example, using:
`replica_group_ids` = {0, 1, 2, 0} for four replicas is invalid.
Computing the result of CrossReplicaSum requires having one input from each
replica, so if one replica executes a CrossReplicaSum node more times than
another, then the former replica will wait forever. Since the replicas are all
......@@ -1299,12 +1308,10 @@ See also
: : : parameters of type T and M of :
: : : arbitrary type :
| `dimensions` | `int64` array | array of map dimensions |
| `static_operands` | sequence of M `XlaOp`s | M arrays of arbitrary type |
Applies a scalar function over the given `operands` arrays, producing an array
of the same dimensions where each element is the result of the mapped function
applied to the corresponding elements in the input arrays with `static_operands`
given as additional input to `computation`.
applied to the corresponding elements in the input arrays.
The mapped function is an arbitrary computation with the restriction that it has
N inputs of scalar type `T` and a single output with type `S`. The output has
......@@ -2003,13 +2010,35 @@ Slice(b, {2, 1}, {4, 3}) produces:
See also
[`XlaBuilder::Sort`](https://www.tensorflow.org/code/tensorflow/compiler/xla/client/xla_client/xla_builder.h).
Sorts the elements in the operand.
There are two versions of the Sort instruction: a single-operand and a
two-operand version.
<b>`Sort(operand)`</b>
Arguments | Type | Semantics
--------- | ------- | --------------------
`operand` | `XlaOp` | The operand to sort.
Sorts the elements in the operand in ascending order. The operand must be rank-1.
If the operand's elements have floating point type, and the operand contains
NaN elements, the order of elements in the output is implementation-defined.
<b>`Sort(key, value)`</b>
Sorts both the key and the value operands. The keys are sorted as in the
single-operand version. The values are sorted according to the order of their
corresponding keys. For example, if the inputs are `keys = [3, 1]` and
`values = [42, 50]`, then the output of the sort is the tuple `{[1, 3], [50, 42]}`.
The sort is not guaranteed to be stable, that is, if the keys array contains
duplicates, the order of their corresponding values may not be preserved.
Arguments | Type | Semantics
--------- | ------- | -------------------
`operand` | `XlaOp` | The operand to sort
`keys` | `XlaOp` | The sort keys.
`values` | `XlaOp` | The values to sort.
The `keys` and `values` operand must both be rank-1, and must have the same
dimensions, but may have different element types.
## Transpose
......
此差异已折叠。
# Custom Training Walkthrough
# Custom training: walkthrough
[Colab notebook](https://colab.research.google.com/github/tensorflow/models/blob/r1.9.0/samples/core/get_started/eager.ipynb)
[Colab notebook](https://colab.research.google.com/github/tensorflow/models/blob/master/samples/core/get_started/eager.ipynb)
# Research and experimentation
Eager execution provides an imperative, define-by-run interface for advanced
operations. Write custom layers, forward passes, and training loops with
auto&nbsp;differentiation. Start with these notebooks, then read the
[eager execution guide](../../guide/eager).
1. <span>[Eager execution](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/notebooks/eager_intro.ipynb){:.external}</span>
2. <span>[Automatic differentiation and gradient tape](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/notebooks/automatic_differentiation.ipynb){:.external}</span>
3. <span>[Custom training: basics](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/notebooks/custom_training.ipynb){:.external}</span>
4. <span>[Custom layers](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/notebooks/custom_layers.ipynb){:.external}</span>
5. [Custom training: walkthrough](/tutorials/eager/custom_training_walkthrough)
6. <span>[Advanced example: Neural machine translation with attention](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/nmt_with_attention/nmt_with_attention.ipynb){:.external}</span>
# How to Retrain Inception's Final Layer for New Categories
**NOTE: This tutorial has moved to**
https://github.com/tensorflow/hub/tree/master/docs/tutorials/image_retraining.md
......@@ -434,7 +434,6 @@ should be able to transfer some of that understanding to solving related
problems. One way to perform transfer learning is to remove the final
classification layer of the network and extract
the [next-to-last layer of the CNN](https://arxiv.org/abs/1310.1531), in this case a 2048 dimensional vector.
There's a guide to doing this @{$image_retraining$in the how-to section}.
## Resources for Learning More
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -135,7 +135,6 @@ for i in range(1000):
DisplayArray(U.eval(), rng=[-0.1, 0.1])
```
![jpeg](../images/pde_output_2.jpg)
![jpeg](../../images/pde_output_2.jpg)
Look! Ripples!
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册