Add absl logging functions to the output_streams supported by tf.print (v2). This ensures we can print to these streams without needing to use tf.compat.v1

PiperOrigin-RevId: 258360763
This commit is contained in:
Tamara Norman 2019-07-16 07:08:11 -07:00 committed by TensorFlower Gardener
parent 2ba24e8d89
commit b542d67952

View File

@ -23,6 +23,7 @@ import pprint
import random import random
import sys import sys
from absl import logging
import six import six
from tensorflow.python import pywrap_tensorflow from tensorflow.python import pywrap_tensorflow
@ -221,10 +222,10 @@ def print_v2(*inputs, **kwargs):
ways), and printable python objects. ways), and printable python objects.
output_stream: The output stream, logging level, or file to print to. output_stream: The output stream, logging level, or file to print to.
Defaults to sys.stderr, but sys.stdout, tf.compat.v1.logging.info, Defaults to sys.stderr, but sys.stdout, tf.compat.v1.logging.info,
tf.compat.v1.logging.warning, and tf.compat.v1.logging.error are also tf.compat.v1.logging.warning, tf.compat.v1.logging.error,
supported. To print to absl.logging.info, absl.logging.warning and absl.loogging,error are also
a file, pass a string started with "file://" followed by the file path, supported. To print to a file, pass a string started with "file://"
e.g., "file:///tmp/foo.out". followed by the file path, e.g., "file:///tmp/foo.out".
summarize: The first and last `summarize` elements within each dimension are summarize: The first and last `summarize` elements within each dimension are
recursively printed per Tensor. If None, then the first 3 and last 3 recursively printed per Tensor. If None, then the first 3 and last 3
elements of each dimension are printed for each tensor. If set to -1, it elements of each dimension are printed for each tensor. If set to -1, it
@ -268,6 +269,15 @@ def print_v2(*inputs, **kwargs):
tf_logging.warn: "log(warning)", tf_logging.warn: "log(warning)",
tf_logging.ERROR: "log(error)", tf_logging.ERROR: "log(error)",
tf_logging.error: "log(error)", tf_logging.error: "log(error)",
logging.INFO: "log(info)",
logging.info: "log(info)",
logging.INFO: "log(info)",
logging.WARNING: "log(warning)",
logging.WARN: "log(warning)",
logging.warning: "log(warning)",
logging.warn: "log(warning)",
logging.ERROR: "log(error)",
logging.error: "log(error)",
} }
if _is_filepath(output_stream): if _is_filepath(output_stream):