tf.contrib.estimator.DNNRegressorWithLayerAnnotations

A regressor for TensorFlow DNN models with layer annotations.

This regressor is functionally identical to estimator.DNNRegressor as far as training and evaluating models is concerned. The key difference is that this classifier adds additional layer annotations, which can be used for computing Integrated Gradients.

Integrated Gradients is a method for attributing a classifier's predictions to its input features (https://arxiv.org/pdf/1703.01365.pdf). Given an input instance, the method assigns attribution scores to individual features in proportion to the feature's importance to the classifier's prediction.

See estimator.DNNRegressor for example code for training and evaluating models using this regressor.

This regressor is checkpoint-compatible with estimator.DNNRegressor and therefore the following should work seamlessly:

Instantiate ordinary estimator as usual.

estimator = tf.estimator.DNNRegressor( config, feature_columns, hidden_units, ...)

Train estimator, export checkpoint.

tf.estimator.train_and_evaluate(estimator, ...)

Instantiate estimator with annotations with the same configuration as the

ordinary estimator.

estimator_with_annotations = ( tf.contrib.estimator.DNNRegressorWithLayerAnnotations( config, feature_columns, hidden_units, ...))

Call export_savedmodel with the same arguments as the ordinary estimator,

using the checkpoint produced for the ordinary estimator.

estimator_with_annotations.export_saved_model( export_dir_base, serving_input_receiver, ... checkpoint_path='/path/to/ordinary/estimator/checkpoint/model.ckpt-1234')

Args
hidden_units Iterable of number hidden units per layer. All layers are fully connected. Ex. [64, 32] means first layer has 64 nodes and second one has 32.
feature_columns An iterable containing all the feature columns used by the model. All items in the set should be instances of classes derived from _FeatureColumn.
model_dir Directory to save model parameters, graph and etc. This can also be used to load checkpoints from the directory into a estimator to continue training a previously saved model.
label_dimension Number of regression targets per example. This is the size of the last dimension of the labels and logits Tensor objects (typically, these have shape [batch_size, label_dimension]).
weight_column A string or a _NumericColumn created by tf.feature_column.numeric_column defining feature column representing weights. It is used to down weight or boost examples during training. It will be multiplied by the loss of the example. If it is a string, it is used as a key to fetch weight tensor from the features. If it is a _NumericColumn, raw tensor is fetched by key weight_column.key, then weight_column.normalizer_fn is applied on it to get weight tensor.
optimizer An instance of tf.Optimizer used to train the model. Defaults to Adagrad optimizer.
activation_fn Activation function applied to each layer. If None, will use tf.nn.relu.
dropout When not None, the probability we will drop out a given coordinate.
input_layer_partitioner Optional. Partitioner for input layer. Defaults to min_max_variable_partitioner with min_slice_size 64 << 20.
config RunConfig object to configure the runtime settings.
warm_start_from A string filepath to a checkpoint to warm-start from, or a WarmStartSettings object to fully configure warm-starting. If the string filepath is provided instead of a WarmStartSettings, then all weights are warm-started, and it is assumed that vocabularies and Tensor names are unchanged.
loss_reduction One of tf.losses.Reduction except NONE. Describes how to reduce training loss over batch. Defaults to SUM.
Returns
DNNRegressor with layer annotations.

© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/estimator/DNNRegressorWithLayerAnnotations