Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect TensorFlow logging to a file?

I'm using TensorFlow-Slim, which has some useful logging printed out to console by tf.logging. I would like to redirect those loggings to a text file, but couldn't find a way doing so. I looked at the tf_logging.py source code, which exposes the following, but doesn't seem to have the option to write logs to a file. Please let me know if I missed something.

__all__ = ['log', 'debug', 'error', 'fatal', 'info', 'warn', 'warning',            'DEBUG', 'ERROR', 'FATAL', 'INFO', 'WARN',            'flush', 'log_every_n', 'log_first_n', 'vlog',            'TaskLevelStatusMessage', 'get_verbosity', 'set_verbosity'] 
like image 800
Ying Xiong Avatar asked Nov 12 '16 04:11

Ying Xiong


People also ask

What is TensorFlow logger?

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. get_logger() is used to get the logger instance. Syntax: tensorflow.get_logger() Parameters: It doesn't accept any parameters. Returns: It returns the logger instance.


2 Answers

import logging  # get TF logger log = logging.getLogger('tensorflow') log.setLevel(logging.DEBUG)  # create formatter and add it to the handlers formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')  # create file handler which logs even debug messages fh = logging.FileHandler('tensorflow.log') fh.setLevel(logging.DEBUG) fh.setFormatter(formatter) log.addHandler(fh) 

My solution is inspired by this thread.

like image 74
matlibplotter Avatar answered Oct 10 '22 01:10

matlibplotter


You are right, there are no knobs for you to do that.

If you truly, positively, absolutely cannot live with that, tf.logging is based on python logging. So, import logging tf.logging._logger.basicConfig(filename='tensorflow.log', level=logging.DEBUG)

Note that you are on your own on an unsupported path, and that behavior may break at anytime.

You may also file a feature request at our github issue page.

like image 22
drpng Avatar answered Oct 10 '22 03:10

drpng