"[AutoGraph](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/autograph/README.md) helps you write complicated graph code using just plain Python -- behind the scenes, AutoGraph automatically transforms your code into the equivalent TF graph code. We support a large chunk of the Python language, which is growing. [Please see this document for what we currently support, and what we're working on](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/autograph/LIMITATIONS.md)."
"[AutoGraph](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/autograph/README.md) helps you write complicated graph code using just plain Python -- behind the scenes, AutoGraph automatically transforms your code into the equivalent TF graph code. We support a large chunk of the Python language, which is growing. [Please see this document for what we currently support, and what we're working on](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/autograph/LIMITATIONS.md)."
]
]
},
},
{
"metadata": {
"id": "n4EKOpw9mObL",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"### Setup"
]
},
{
{
"metadata": {
"metadata": {
"id": "mT7meGqrZTz9",
"id": "mT7meGqrZTz9",
...
@@ -103,12 +114,26 @@
...
@@ -103,12 +114,26 @@
"\n",
"\n",
"import tensorflow as tf\n",
"import tensorflow as tf\n",
"from tensorflow.contrib import autograph\n",
"from tensorflow.contrib import autograph\n",
"tf.enable_eager_execution()\n",
"\n",
"\n",
"import matplotlib.pyplot as plt"
"import matplotlib.pyplot as plt"
],
],
"execution_count": 0,
"execution_count": 0,
"outputs": []
"outputs": []
},
},
{
"metadata": {
"id": "ohbSnA79mcJV",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
"## Automatically converting control flow\n",
"\n",
"AutoGraph can convert a large chunk of the Python language into equivalent graph-construction code, and we're adding new supported language features all the time. In this section, we'll give you a taste of some of the functionality in AutoGraph.\n",
"AutoGraph will automatically convert most Python control flow statements into their correct graph equivalent. "
]
},
{
{
"metadata": {
"metadata": {
"id": "Ry0TlspBZVvf",
"id": "Ry0TlspBZVvf",
...
@@ -144,7 +169,7 @@
...
@@ -144,7 +169,7 @@
},
},
"cell_type": "markdown",
"cell_type": "markdown",
"source": [
"source": [
"Into graph-compatible functions like this:"
"Into graph-building functions like this:"
]
]
},
},
{
{
...
@@ -167,7 +192,7 @@
...
@@ -167,7 +192,7 @@
},
},
"cell_type": "markdown",
"cell_type": "markdown",
"source": [
"source": [
"You can take code written for eager execution and run it in graph mode. You get the same results, but with all the benfits of graphs:"
"You can take code written for eager execution and run it in a `tf.Graph`. You get the same results, but with all the benfits of graphs:"
"AutoGraph can convert a large chunk of the Python language into equivalent graph-construction code, and we're adding new supported language features all the time. In this section, we'll give you a taste of some of the functionality in AutoGraph.\n",
"AutoGraph will automatically convert most Python control flow statements into their correct graph equivalent. \n",
" \n",
"\n",
"We support common statements like `while`, `for`, `if`, `break`, `return` and more. You can even nest them as much as you like. Imagine trying to write the graph version of this code by hand:\n"
"We support common statements like `while`, `for`, `if`, `break`, `return` and more. You can even nest them as much as you like. Imagine trying to write the graph version of this code by hand:\n"