tf.contrib.estimator.add_metrics(
estimator,
metric_fn
)
Defined in tensorflow/contrib/estimator/python/estimator/extenders.py.
Creates a new tf.estimator.Estimator which has given metrics.
Example:
def my_auc(labels, predictions):
return {'auc': tf.metrics.auc(labels, predictions['logistic'])}
estimator = tf.estimator.DNNClassifier(...)
estimator = tf.contrib.estimator.add_metrics(estimator, my_auc)
estimator.train(...)
estimator.evaluate(...)
Example usage of custom metric which uses features:
def my_auc(features, labels, predictions):
return {'auc': tf.metrics.auc(
labels, predictions['logistic'], weights=features['weight'])}
estimator = tf.estimator.DNNClassifier(...)
estimator = tf.contrib.estimator.add_metrics(estimator, my_auc)
estimator.train(...)
estimator.evaluate(...)
estimator: A tf.estimator.Estimator object.metric_fn: A function which should obey the following signature:Tensor or dict of Tensor created by given estimator.dict of Tensor objects created by input_fn which is given to estimator.evaluate as an argument.Tensor or dict of Tensor created by input_fn which is given to estimator.evaluate as an argument.estimator.estimator's existing metrics. If there is a name conflict between this and estimators existing metrics, this will override the existing one. The values of the dict are the results of calling a metric function, namely a (metric_tensor, update_op) tuple.A new tf.estimator.Estimator which has a union of original metrics with given ones.
© 2018 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/api_docs/python/tf/contrib/estimator/add_metrics