Skip to content

Commit 5e5dc40

Browse files
committed
Merge commit for internal changes
2 parents c7751cf + 945205d commit 5e5dc40

File tree

2 files changed

+63
-54
lines changed

2 files changed

+63
-54
lines changed

get_started/checkpoints.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This document focuses on checkpoints. For details on SavedModel, see the
1616
## Sample code
1717

1818
This document relies on the same
19-
[https://github.com/tensorflow/models/blob/master/samples/core/get_started/premade_estimator.py](Iris classification example) detailed in @{$premade_estimators$Getting Started with TensorFlow}.
19+
[Iris classification example](https://github.com/tensorflow/models/blob/master/samples/core/get_started/premade_estimator.py) detailed in @{$premade_estimators$Getting Started with TensorFlow}.
2020
To download and access the example, invoke the following two commands:
2121

2222
```shell

get_started/premade_estimators.md

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,39 @@
22
# Getting Started with TensorFlow
33

44
This document introduces the TensorFlow programming environment and shows you
5-
how to write the Iris classification problem in TensorFlow.
5+
how to solve the Iris classification problem in TensorFlow.
66

7-
Prior to reading this document, do the following:
7+
## Prerequisites
8+
9+
Prior to using the sample code in this document, you'll need to do the
10+
following:
811

912
* @{$install$Install TensorFlow}.
1013
* If you installed TensorFlow with virtualenv or Anaconda, activate your
1114
TensorFlow environment.
12-
* To keep the data import simple, our Iris example uses Pandas. You can
13-
install Pandas with:
15+
* Install or upgrade pandas by issuing the following command:
1416

15-
`pip install pandas`
17+
pip install pandas
1618

1719
## Getting the sample code
1820

19-
Take the following steps to get the sample code for this program:
21+
Take the following steps to get the sample code we'll be going through:
2022

21-
1. Clone the TensorFlow Models repository from github by entering the following
23+
1. Clone the TensorFlow Models repository from GitHub by entering the following
2224
command:
2325

24-
`git clone https://github.com/tensorflow/models`
26+
git clone https://github.com/tensorflow/models
2527

2628
1. Change directory within that branch to the location containing the examples
2729
used in this document:
2830

29-
`cd models/samples/core/get_started/`
31+
cd models/samples/core/get_started/
3032

3133
The program described in this document is
3234
[`premade_estimator.py`](https://github.com/tensorflow/models/blob/master/samples/core/get_started/premade_estimator.py).
3335
This program uses
3436
[`iris_data.py`](https://github.com/tensorflow/models/blob/master/samples/core/get_started/iris_data.py)
35-
To fetch its training data.
37+
to fetch its training data.
3638

3739
### Running the program
3840

@@ -45,7 +47,7 @@ python premade_estimator.py
4547
The program should output training logs followed by some predictions against
4648
the test set. For example, the first line in the following output shows that
4749
the model thinks there is a 99.6% chance that the first example in the test
48-
set is a Setosa. Since the test set `expected "Setosa"`, this appears to be
50+
set is a Setosa. Since the test set expected Setosa, this appears to be
4951
a good prediction.
5052

5153
``` None
@@ -61,9 +63,9 @@ If the program generates errors instead of answers, ask yourself the following
6163
questions:
6264

6365
* Did you install TensorFlow properly?
64-
* Are you using the correct version of tensorflow?
66+
* Are you using the correct version of TensorFlow?
6567
* Did you activate the environment you installed TensorFlow in? (This is
66-
only relevant in certain installation environments.)
68+
only relevant in certain installation mechanisms.)
6769

6870
## The programming stack
6971

@@ -74,18 +76,15 @@ provides a programming stack consisting of multiple API layers:
7476
<div style="width:100%; margin:auto; margin-bottom:10px; margin-top:20px;">
7577
<img style="width:100%" src="../images/tensorflow_programming_environment.png">
7678
</div>
77-
<div style="text-align: center">
78-
The TensorFlow Programming Environment
79-
</div>
8079

8180
We strongly recommend writing TensorFlow programs with the following APIs:
8281

83-
* @{tf.estimator$Estimators}, which represent a complete model.
82+
* @{$programmers_guide/estimators$Estimators}, which represent a complete model.
8483
The Estimator API provides methods to train the model, to judge the model's
8584
accuracy, and to generate predictions.
8685
* @{$get_started/datasets_quickstart$Datasets}, which build a data input
8786
pipeline. The Dataset API has methods to load and manipulate data, and feed
88-
it into your model. The Datasets API meshes well with the Estimators API.
87+
it into your model. The Dataset API meshes well with the Estimators API.
8988

9089
## Classifying irises: an overview
9190

@@ -120,7 +119,7 @@ individual Iris flowers:
120119
* petal length
121120
* petal width
122121

123-
Our model will represent these features as float32 numerical data.
122+
Our model will represent these features as `float32` numerical data.
124123

125124
The label identifies the Iris species, which must be one of the following:
126125

@@ -154,9 +153,6 @@ The following figure illustrates the features, hidden layers, and predictions
154153
alt="A diagram of the network architecture: Inputs, 2 hidden layers, and outputs"
155154
src="../images/custom_estimators/full_network.png">
156155
</div>
157-
<div style="text-align: center">
158-
The Model.
159-
</div>
160156

161157
### Inference
162158

@@ -174,12 +170,12 @@ example is an Iris Versicolor.
174170

175171
## Overview of programming with Estimators
176172

177-
An Estimator is TensorFlow's high level representation of a complete model. It
173+
An Estimator is TensorFlow's high-level representation of a complete model. It
178174
handles the details of initialization, logging, saving and restoring, and many
179175
other features so you can concentrate on your model. For more details see
180176
@{$programmers_guide/estimators}.
181177

182-
An "Estimator" is any class derived from @{tf.estimator.Estimator}. TensorFlow
178+
An Estimator is any class derived from @{tf.estimator.Estimator}. TensorFlow
183179
provides a collection of
184180
[pre-made Estimators](https://developers.google.com/machine-learning/glossary/#pre-made_Estimator)
185181
(for example, `LinearRegressor`) to implement common ML algorithms. Beyond
@@ -199,7 +195,7 @@ following tasks:
199195
* Call one or more methods on the Estimator object, passing the appropriate
200196
input function as the source of the data.
201197

202-
Let's see how those tasks are implemented in Iris.
198+
Let's see how those tasks are implemented for Iris classification.
203199

204200
## Create input functions
205201

@@ -209,41 +205,54 @@ evaluating, and prediction.
209205
An **input function** is a function that returns a @{tf.data.Dataset} object
210206
which outputs the following two-element tuple:
211207

212-
* "features" - A Python dictionary in which:
208+
* [`features`](https://developers.google.com/machine-learning/glossary/#feature) - A Python dictionary in which:
213209
* Each key is the name of a feature.
214210
* Each value is an array containing all of that feature's values.
215-
* "label" - An array containing the values of the
211+
* `label` - An array containing the values of the
216212
[label](https://developers.google.com/machine-learning/glossary/#label) for
217213
every example.
218214

219-
Your input function may generate the "features" dictionary and "label" list any
220-
way you like. However, we recommend using TensorFlow's @{tf.data.Dataset} API,
221-
which can deftly parse all sorts of data. At a high-level,
222-
the @{tf.data.Dataset} API consists of the following classes:
215+
Just to demonstrate the format of the input function, here's a simple
216+
implementation:
217+
218+
```python
219+
def input_evaluation_set():
220+
features = {'SepalLength': np.array([6.4, 5.0]),
221+
'SepalWidth': np.array([2.8, 2.3]),
222+
'PetalLength': np.array([5.6, 3.3]),
223+
'PetalWidth': np.array([2.2, 1.0])}
224+
labels = np.array([2, 1])
225+
return features, labels
226+
```
227+
228+
Your input function may generate the `features` dictionary and `label` list any
229+
way you like. However, we recommend using TensorFlow's Dataset API, which can
230+
parse all sorts of data. At a high level, the Dataset API consists of the
231+
following classes:
223232

224233
<div style="width:80%; margin:auto; margin-bottom:10px; margin-top:20px;">
225234
<img style="width:100%"
226235
alt="A diagram showing subclasses of the Dataset class"
227236
src="../images/dataset_classes.png">
228237
</div>
229238

239+
Where the individual members are:
230240

231-
Where:
232-
233-
* Dataset: Base class containing methods to create and transform datasets. Also
234-
allows you to initialize a dataset from data in memory, or from a Python
235-
generator.
236-
* TextLineDataset: Reads lines from text files.
237-
* TFRecordDataset: Reads records from TFRecord files.
238-
* FixedLengthRecordDataset: Reads fixed size records from binary files.
239-
* Iterator: Provides a way to access one data set element at a time.
241+
* `Dataset` - Base class containing methods to create and transform
242+
datasets. Also allows you to initialize a dataset from data in memory, or from
243+
a Python generator.
244+
* `TextLineDataset` - Reads lines from text files.
245+
* `TFRecordDataset` - Reads records from TFRecord files.
246+
* `FixedLengthRecordDataset` - Reads fixed size records from binary files.
247+
* `Iterator` - Provides a way to access one data set element at a time.
240248

241249
The Dataset API can handle a lot of common cases for you. For example,
242250
using the Dataset API, you can easily read in records from a large collection
243251
of files in parallel and join them into a single stream.
244252

245-
To keep things simple in this example we are going to load the data with pandas,
246-
and build our input pipeline from this in-memory data.
253+
To keep things simple in this example we are going to load the data with
254+
[pandas](https://pandas.pydata.org/), and build our input pipeline from this
255+
in-memory data.
247256

248257
Here is the input function used for training in this program, which is available
249258
in [`iris_data.py`](https://github.com/tensorflow/models/blob/master/samples/core/get_started/iris_data.py):
@@ -258,9 +267,9 @@ def train_input_fn(features, labels, batch_size):
258267
return dataset.shuffle(1000).repeat().batch(batch_size)
259268
```
260269

261-
## Define the Feature Columns
270+
## Define the feature columns
262271

263-
A [**Feature Column**](https://developers.google.com/machine-learning/glossary/#feature_columns)
272+
A [**feature column**](https://developers.google.com/machine-learning/glossary/#feature_columns)
264273
is an object describing how the model should use raw input data from the
265274
features dictionary. When you build an Estimator model, you pass it a list of
266275
feature columns that describes each of the features you want the model to use.
@@ -270,7 +279,7 @@ to the model.
270279
For Iris, the 4 raw features are numeric values, so we'll build a list of
271280
feature columns to tell the Estimator model to represent each of the four
272281
features as 32-bit floating-point values. Therefore, the code to create the
273-
Feature Column is simply:
282+
feature column is:
274283

275284
```python
276285
# Feature columns describe how to use the input.
@@ -279,29 +288,29 @@ for key in train_x.keys():
279288
my_feature_columns.append(tf.feature_column.numeric_column(key=key))
280289
```
281290

282-
Feature Columns can be far more sophisticated than those we're showing here.
283-
We detail feature columns @{$get_started/feature_columns$later on} in
284-
getting started.
291+
Feature columns can be far more sophisticated than those we're showing here. We
292+
detail feature columns @{$get_started/feature_columns$later on} in our Getting
293+
Started guide.
285294

286295
Now that we have the description of how we want the model to represent the raw
287296
features, we can build the estimator.
288297

289298

290-
## Instantiate an Estimator
299+
## Instantiate an estimator
291300

292301
The Iris problem is a classic classification problem. Fortunately, TensorFlow
293302
provides several pre-made classifier Estimators, including:
294303

295-
* @{tf.estimator.DNNClassifier}for deep models that perform multi-class
304+
* @{tf.estimator.DNNClassifier} for deep models that perform multi-class
296305
classification.
297-
* @{tf.estimator.DNNLinearCombinedClassifier}for wide-n-deep models.
298-
* @{tf.estimator.LinearClassifier} for classifiers based on linear models.
306+
* @{tf.estimator.DNNLinearCombinedClassifier} for wide & deep models.
307+
* @{tf.estimator.LinearClassifier} for classifiers based on linear models.
299308

300309
For the Iris problem, `tf.estimator.DNNClassifier` seems like the best choice.
301310
Here's how we instantiated this Estimator:
302311

303312
```python
304-
# Build 2 hidden layer DNN with 10, 10 units respectively.
313+
# Build a DNN with 2 hidden layers and 10 nodes in each hidden layer.
305314
classifier = tf.estimator.DNNClassifier(
306315
feature_columns=my_feature_columns,
307316
# Two hidden layers of 10 nodes each.

0 commit comments

Comments
 (0)