tensorflow生成日志文件

tensorflow生成日志文件

1、在代码中加入这一段:设定日志等级、指定日志文件名称等

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('loss.log')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
log.addHandler(fh)

2、复制一份tensor以便写入到日志文件中,例如:

  tf.identity(foreground_loss, name='foreground_loss')

3、写入到日志文件命令:例如

    tensors_to_log = {
      # 'learning_rate': 'learning_rate',
      # 'focal_loss': 'focal_class_imbalance_loss',
      # 'train_px_accuracy': 'train_px_accuracy',
      # 'train_mean_iou': 'train_mean_iou',
	  'global_step':'global_step',
      'foreground_loss':'foreground_loss',
      'background_loss':'background_loss',
    }

以上为个人见解,难免有错,如有发现错误还望指出。

猜你喜欢

转载自blog.csdn.net/lfs666666/article/details/85376941