aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Billy Lamberta <blamb@google.com>2018-06-28 23:11:45 -0700
committerGravatar Billy Lamberta <blamb@google.com>2018-07-02 15:18:10 -0700
commit152b830b379e7d4ec0db9aac111a732db37e19c3 (patch)
tree4ad586c2c9e1ad3ff2f2c8c161bf918f5853f9a9
parent47d4d0ab70c98d8935d9abc4f4829ded2cd3d8c0 (diff)
Move datasets notebook as section in eager_intro
-rw-r--r--tensorflow/contrib/eager/python/examples/notebooks/datasets.ipynb237
-rw-r--r--tensorflow/contrib/eager/python/examples/notebooks/eager_intro.ipynb132
2 files changed, 126 insertions, 243 deletions
diff --git a/tensorflow/contrib/eager/python/examples/notebooks/datasets.ipynb b/tensorflow/contrib/eager/python/examples/notebooks/datasets.ipynb
deleted file mode 100644
index ba6602cb16..0000000000
--- a/tensorflow/contrib/eager/python/examples/notebooks/datasets.ipynb
+++ /dev/null
@@ -1,237 +0,0 @@
-{
- "nbformat": 4,
- "nbformat_minor": 0,
- "metadata": {
- "colab": {
- "name": "datasets.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": "hvpDiXDuuNEu",
- "colab_type": "text"
- },
- "cell_type": "markdown",
- "source": [
- "##### Copyright 2018 The TensorFlow Authors."
- ]
- },
- {
- "metadata": {
- "id": "4FWzUGc7uQKr",
- "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": "RRbeuncot80C",
- "colab_type": "text"
- },
- "cell_type": "markdown",
- "source": [
- "# Datasets"
- ]
- },
- {
- "metadata": {
- "id": "i9rtB6DnuFw5",
- "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/datasets.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/datasets.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": "U9i2Dsh-ziXr",
- "colab_type": "text"
- },
- "cell_type": "markdown",
- "source": [
- "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."
- ]
- },
- {
- "metadata": {
- "id": "RlIWhyeLoYnG",
- "colab_type": "code",
- "colab": {
- "autoexec": {
- "startup": false,
- "wait_interval": 0
- }
- },
- "cellView": "code"
- },
- "cell_type": "code",
- "source": [
- "# Import TensorFlow.\n",
- "import tensorflow as tf\n",
- "\n",
- "# Enable eager execution\n",
- "tf.enable_eager_execution()"
- ],
- "execution_count": 0,
- "outputs": []
- },
- {
- "metadata": {
- "id": "H9UySOPLXdaw",
- "colab_type": "text"
- },
- "cell_type": "markdown",
- "source": [
- "## 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."
- ]
- },
- {
- "metadata": {
- "id": "WPTUfGq6kJ5w",
- "colab_type": "code",
- "colab": {
- "autoexec": {
- "startup": false,
- "wait_interval": 0
- }
- },
- "cellView": "code"
- },
- "cell_type": "code",
- "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"
- ],
- "execution_count": 0,
- "outputs": []
- },
- {
- "metadata": {
- "id": "twBfWd5xyu_d",
- "colab_type": "text"
- },
- "cell_type": "markdown",
- "source": [
- "## 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."
- ]
- },
- {
- "metadata": {
- "id": "ngUe237Wt48W",
- "colab_type": "code",
- "colab": {
- "autoexec": {
- "startup": false,
- "wait_interval": 0
- }
- },
- "cellView": "code"
- },
- "cell_type": "code",
- "source": [
- "ds_tensors = ds_tensors.map(tf.square).shuffle(2).batch(2)\n",
- "ds_file = ds_file.batch(2)"
- ],
- "execution_count": 0,
- "outputs": []
- },
- {
- "metadata": {
- "id": "IDY4WsYRhP81",
- "colab_type": "text"
- },
- "cell_type": "markdown",
- "source": [
- "## 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."
- ]
- },
- {
- "metadata": {
- "id": "lCUWzso6mbqR",
- "colab_type": "code",
- "colab": {
- "autoexec": {
- "startup": false,
- "wait_interval": 0
- }
- }
- },
- "cell_type": "code",
- "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)"
- ],
- "execution_count": 0,
- "outputs": []
- }
- ]
-} \ No newline at end of file
diff --git a/tensorflow/contrib/eager/python/examples/notebooks/eager_intro.ipynb b/tensorflow/contrib/eager/python/examples/notebooks/eager_intro.ipynb
index a00893bc77..5311a33e6e 100644
--- a/tensorflow/contrib/eager/python/examples/notebooks/eager_intro.ipynb
+++ b/tensorflow/contrib/eager/python/examples/notebooks/eager_intro.ipynb
@@ -3,7 +3,7 @@
"nbformat_minor": 0,
"metadata": {
"colab": {
- "name": "Eager execution introduction",
+ "name": "eager_intro.ipynb",
"version": "0.3.2",
"views": {},
"default_view": {},
@@ -92,7 +92,8 @@
"\n",
"* Importing required packages\n",
"* Creating and using Tensors\n",
- "* Using GPU acceleration"
+ "* Using GPU acceleration\n",
+ "* Datasets"
]
},
{
@@ -356,16 +357,135 @@
},
{
"metadata": {
- "id": "YEOJTNiOvnpQ",
+ "id": "o1K4dlhhHtQj",
"colab_type": "text"
},
"cell_type": "markdown",
"source": [
- "## Next Steps\n",
+ "## Datasets\n",
"\n",
- "In this tutorial we covered the most fundamental concepts in TensorFlow - `Tensor`s, operations, and devices.\n",
- "In [the next tutorial](https://github.com/tensorflow/models/tree/master/official/contrib/eager/python/examples/notebooks/2_gradients.ipynb) we will cover automatic differentiation - a building block required for training many machine learning models like neural networks."
+ "This section demonstrates the use of the [`tf.data.Dataset` API](https://www.tensorflow.org/guide/datasets) to build pipelines to feed data to your model. 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."
+ ]
+ },
+ {
+ "metadata": {
+ "id": "zI0fmOynH-Ne",
+ "colab_type": "text"
+ },
+ "cell_type": "markdown",
+ "source": [
+ "### 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."
+ ]
+ },
+ {
+ "metadata": {
+ "id": "F04fVOHQIBiG",
+ "colab_type": "code",
+ "colab": {
+ "autoexec": {
+ "startup": false,
+ "wait_interval": 0
+ }
+ }
+ },
+ "cell_type": "code",
+ "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",
+ "\n",
+ "with open(filename, 'w') as f:\n",
+ " f.write(\"\"\"Line 1\n",
+ "Line 2\n",
+ "Line 3\n",
+ " \"\"\")\n",
+ "\n",
+ "ds_file = tf.data.TextLineDataset(filename)"
+ ],
+ "execution_count": 0,
+ "outputs": []
+ },
+ {
+ "metadata": {
+ "id": "vbxIhC-5IPdf",
+ "colab_type": "text"
+ },
+ "cell_type": "markdown",
+ "source": [
+ "### 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."
]
+ },
+ {
+ "metadata": {
+ "id": "uXSDZWE-ISsd",
+ "colab_type": "code",
+ "colab": {
+ "autoexec": {
+ "startup": false,
+ "wait_interval": 0
+ }
+ }
+ },
+ "cell_type": "code",
+ "source": [
+ "ds_tensors = ds_tensors.map(tf.square).shuffle(2).batch(2)\n",
+ "\n",
+ "ds_file = ds_file.batch(2)"
+ ],
+ "execution_count": 0,
+ "outputs": []
+ },
+ {
+ "metadata": {
+ "id": "A8X1GNfoIZKJ",
+ "colab_type": "text"
+ },
+ "cell_type": "markdown",
+ "source": [
+ "### 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."
+ ]
+ },
+ {
+ "metadata": {
+ "id": "ws-WKRk5Ic6-",
+ "colab_type": "code",
+ "colab": {
+ "autoexec": {
+ "startup": false,
+ "wait_interval": 0
+ }
+ }
+ },
+ "cell_type": "code",
+ "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)"
+ ],
+ "execution_count": 0,
+ "outputs": []
}
]
} \ No newline at end of file