From 22c257684931e851aabc8787daf5f5b32e7aae63 Mon Sep 17 00:00:00 2001 From: wangguanzhong Date: Mon, 9 Sep 2019 17:04:39 +0800 Subject: [PATCH] print total config (#3300) --- tools/__init__.py | 13 +++++++++++++ tools/configure.py | 10 +++++++--- tools/eval.py | 2 ++ tools/infer.py | 4 ++++ tools/train.py | 3 ++- 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 tools/__init__.py diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 000000000..d0c32e260 --- /dev/null +++ b/tools/__init__.py @@ -0,0 +1,13 @@ +# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/tools/configure.py b/tools/configure.py index 8b43b00bc..4a565aed9 100644 --- a/tools/configure.py +++ b/tools/configure.py @@ -151,9 +151,7 @@ def generate_config(**kwargs): print(dump_config(s, minimal)) -# FIXME this is pretty hackish, maybe implement a custom YAML printer? -def analyze_config(**kwargs): - config = load_config(kwargs['file']) +def print_total_cfg(config): modules = get_registered_modules() green = '___{}___'.format(color_tty.colors.index('green') + 31) @@ -222,6 +220,12 @@ def analyze_config(**kwargs): print(buffer) +# FIXME this is pretty hackish, maybe implement a custom YAML printer? +def analyze_config(**kwargs): + config = load_config(kwargs['file']) + print_total_cfg(config) + + if __name__ == '__main__': argv = sys.argv[1:] diff --git a/tools/eval.py b/tools/eval.py index eea606ec3..089beec22 100644 --- a/tools/eval.py +++ b/tools/eval.py @@ -33,6 +33,7 @@ set_paddle_flags( import paddle.fluid as fluid +from tools.configure import print_total_cfg from ppdet.utils.eval_utils import parse_fetches, eval_run, eval_results, json_eval_results import ppdet.utils.checkpoint as checkpoint from ppdet.utils.cli import ArgsParser @@ -61,6 +62,7 @@ def main(): # check if set use_gpu=True in paddlepaddle cpu version check_gpu(cfg.use_gpu) + print_total_cfg(cfg) if 'eval_feed' not in cfg: eval_feed = create(main_arch + 'EvalFeed') diff --git a/tools/infer.py b/tools/infer.py index ac1fd215b..47684ed5d 100644 --- a/tools/infer.py +++ b/tools/infer.py @@ -22,11 +22,13 @@ import glob import numpy as np from PIL import Image + def set_paddle_flags(**kwargs): for key, value in kwargs.items(): if os.environ.get(key, None) is None: os.environ[key] = str(value) + # NOTE(paddle-dev): All of these flags should be set before # `import paddle`. Otherwise, it would not take any effect. set_paddle_flags( @@ -35,6 +37,7 @@ set_paddle_flags( from paddle import fluid +from tools.configure import print_total_cfg from ppdet.core.workspace import load_config, merge_config, create from ppdet.modeling.model_input import create_feed from ppdet.data.data_feed import create_reader @@ -147,6 +150,7 @@ def main(): # check if set use_gpu=True in paddlepaddle cpu version check_gpu(cfg.use_gpu) + print_total_cfg(cfg) if 'test_feed' not in cfg: test_feed = create(main_arch + 'TestFeed') diff --git a/tools/train.py b/tools/train.py index 95bba5fd2..c6a40842c 100644 --- a/tools/train.py +++ b/tools/train.py @@ -21,6 +21,7 @@ import time import numpy as np import datetime from collections import deque +from tools.configure import print_total_cfg def set_paddle_flags(**kwargs): @@ -36,7 +37,6 @@ set_paddle_flags( ) from paddle import fluid - from ppdet.core.workspace import load_config, merge_config, create from ppdet.data.data_feed import create_reader @@ -66,6 +66,7 @@ def main(): # check if set use_gpu=True in paddlepaddle cpu version check_gpu(cfg.use_gpu) + print_total_cfg(cfg) if cfg.use_gpu: devices_num = fluid.core.get_cuda_device_count() -- GitLab