From de7b6548811b2c4ce64215f839c2aaf52f6b3847 Mon Sep 17 00:00:00 2001 From: frankwhzhang Date: Mon, 10 Aug 2020 16:24:26 +0800 Subject: [PATCH] add logging for info --- core/trainers/framework/runner.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/core/trainers/framework/runner.py b/core/trainers/framework/runner.py index 16c452ea..baab7315 100644 --- a/core/trainers/framework/runner.py +++ b/core/trainers/framework/runner.py @@ -17,12 +17,15 @@ from __future__ import print_function import os import time import numpy as np -from datetime import datetime +import logging import paddle.fluid as fluid from paddlerec.core.utils import envs from paddlerec.core.metric import Metric +logging.basicConfig( + format='%(asctime)s - %(levelname)s: %(message)s', level=logging.INFO) + __all__ = [ "RunnerBase", "SingleRunner", "PSRunner", "CollectiveRunner", "PslibRunner" ] @@ -142,9 +145,9 @@ class RunnerBase(object): metrics_format = [] if context["is_infer"]: - metrics_format.append("{{}}\t[Infer]\t{}: {{}}".format("batch")) + metrics_format.append("\t[Infer]\t{}: {{}}".format("batch")) else: - metrics_format.append("{{}}\t[Train]\t{}: {{}}".format("batch")) + metrics_format.append("\t[Train]\t{}: {{}}".format("batch")) metrics_format.append("{}: {{:.2f}}s".format("time_each_interval")) @@ -170,10 +173,7 @@ class RunnerBase(object): return_numpy=False) if batch_id % fetch_period == 0 and batch_id != 0: - metrics = [ - datetime.now().strftime('%Y-%m-%d %H:%M:%S') - ] - metrics.extend([batch_id]) + metrics = [batch_id] end_time = time.time() seconds = end_time - begin_time metrics.extend([seconds]) @@ -184,8 +184,7 @@ class RunnerBase(object): for metrics_tensor in metrics_tensors ] metrics.extend(metrics_rets) - - print(metrics_format.format(*metrics)) + logging.info(metrics_format.format(*metrics)) batch_id += 1 except fluid.core.EOFException: reader.reset() -- GitLab