-
Notifications
You must be signed in to change notification settings - Fork 0
/
Estimator
39 lines (34 loc) · 1.83 KB
/
Estimator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Introduction
1.Estimator encapsulates 4 functions of ML project: train, evaluation, prediction, serving.
2.Run estimator based model on local or distributed evironment; on CPUs or GPUs without changing model.
3.Estimator provides a distributed train loop: build graph, init variables, load data, checkpoint model, summary for tensorboard
4. Seperate data input from model
# A estimator program
## Input_fn
Return a Dataset object which contains the tuple: (features, labels). Note that features and lebels are in the one element of Dataset
1.features: a dict with key as the feature names (which will be used in specify feature columns) and value as the tensor
2.labels: a tensor
## Feature columns
1. feature column class works like a specification: describing how the model should use raw input data from the features dict
## Estimator
1. Instantiate an estimator object and pass the feature column objects to params arg.
## Call methods of estimator
1. Call train, inference, evaluation method and pass input_fn
# Configure checkpoints
1. model_dir of tf.estimator specify the dir of model file and event file (for tensorboard)
2. Create a tf.estimator.RunConfig object that defines the checkpoint schedule and pass it to config of estimator
3. Train, evaluate, inference methods create a new model graph and initialize the variables from checkpoint file
# Custom estimators
##Basics
1. Instantiate a tf.estimator.Estimator and pass a model_fn to it
2. Try to utilize Layer and Metrics API
## Procedure
1. input_fn
2. Feature columns: a list of feature_column object, pass it to params arg of Estimator
3. model_fn
## model_fn
1. Define model graph
2. Define additional calculations for train, eval, predict mode.
3. Return EstimatorSpec
4. train: loss + train_op; eval: loss + dict of eval metrics; predict: logits + prob + class_ids
5. Add summary to tensorboard