Printing extra training metrics with Tensorflow Estimator
From what I've read it is not possible to change it by passing parameter. You can try to do by creating a logging hook and passing it into to estimator run.
In the body of model_fn
function for your estimator:
logging_hook = tf.train.LoggingTensorHook({"loss" : loss,
"accuracy" : accuracy}, every_n_iter=10)
# Rest of the function
return tf.estimator.EstimatorSpec(
...params...
training_hooks = [logging_hook])
EDIT:
To see the output you must also set logging verbosity high enough (unless its your default):
tf.logging.set_verbosity(tf.logging.INFO)
You can also use the TensorBoard to see some graphics of the desired metrics. To do that, add the metric to a TensorFlow summary like this:
accuracy = tf.metrics.accuracy(labels=labels, predictions=predictions["classes"])
tf.summary.scalar('accuracy', accuracy[1])
The cool thing when you use the tf.estimator.Estimator
is that you don't need to add the summaries to a FileWriter
, since it's done automatically (merging and saving them periodically by default - on average every 100 steps).
Don't forget to change this line as well, based on the accuracy
parameter you just added:
eval_metric_ops = { "accuracy": accuracy }
return tf.estimator.EstimatorSpec(
mode=mode, loss=loss, eval_metric_ops=eval_metric_ops)
In order to see the TensorBoard you need to open a new terminal and type:
tensorboard --logdir={$MODEL_DIR}
After that you will be able to see the graphics in your browser at localhost:6006
.