From f6d0103442e3692c396ab27234fdacd622eab595 Mon Sep 17 00:00:00 2001 From: WuHaobo Date: Mon, 20 Apr 2020 21:16:04 +0800 Subject: [PATCH] add ad --- .pre-commit-config.yaml | 15 ++++++++++++-- ppcls/utils/config.py | 37 +++++++++++---------------------- ppcls/utils/logger.py | 46 +++++++++++++++++++++++++++-------------- tools/train.py | 16 ++++++-------- 4 files changed, 61 insertions(+), 53 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f0902299..676872ba 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,20 +4,31 @@ - id: yapf files: \.py$ +- repo: https://github.com/pre-commit/mirrors-autopep8 + rev: v1.5 + hooks: + - id: autopep8 + - repo: https://github.com/pre-commit/pre-commit-hooks - sha: a11d9314b22d8f8c7556443875b731ef05965464 + rev: v2.5.0 hooks: - id: flake8 args: ['--ignore=E265'] - id: check-yaml - id: check-merge-conflict - - id: check-symlinks - id: detect-private-key files: (?!.*paddle)^.*$ - id: end-of-file-fixer files: \.(md|yml)$ - id: trailing-whitespace files: \.(md|yml)$ + - id: check-case-conflict + +- repo: https://github.com/asottile/reorder_python_imports + rev: v1.9.0 + hooks: + - id: reorder-python-imports + args: [--py3-plus] - repo: https://github.com/Lucas-C/pre-commit-hooks sha: v1.0.1 diff --git a/ppcls/utils/config.py b/ppcls/utils/config.py index 524d9a6e..e1674314 100644 --- a/ppcls/utils/config.py +++ b/ppcls/utils/config.py @@ -1,18 +1,18 @@ -#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. +# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # -#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 +# 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 +# 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. - +# 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. import os + import yaml from ppcls.utils import check @@ -84,20 +84,7 @@ def print_config(config): Arguments: config: configs """ - copyright = "PaddleClas is powered by PaddlePaddle !" - info = "For more info please go to the following website." - website = "https://github.com/PaddlePaddle/PaddleClas" - AD_LEN = 55 - - logger.info("\n{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n{7}\n".format( - "=" * (AD_LEN + 4), - "=={}==".format(copyright.center(AD_LEN)), - "=" * (AD_LEN + 4), - "=={}==".format(' ' * AD_LEN), - "=={}==".format(info.center(AD_LEN)), - "=={}==".format(' ' * AD_LEN), - "=={}==".format(website.center(AD_LEN)), - "=" * (AD_LEN + 4), )) + logger.advertisement() print_dict(config) diff --git a/ppcls/utils/logger.py b/ppcls/utils/logger.py index 67b8d9ab..20575c32 100644 --- a/ppcls/utils/logger.py +++ b/ppcls/utils/logger.py @@ -1,26 +1,23 @@ -#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. +# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # -#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 +# 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. - -import os +# 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. import logging logging.basicConfig() -import random -DEBUG = logging.DEBUG #10 -INFO = logging.INFO #20 -WARN = logging.WARN #30 -ERROR = logging.ERROR #40 +DEBUG = logging.DEBUG # 10 +INFO = logging.INFO # 20 +WARN = logging.WARN # 30 +ERROR = logging.ERROR # 40 class Logger(object): @@ -72,3 +69,20 @@ def warning(fmt, *args): def error(fmt, *args): """error""" _logger.error(fmt, *args) + + +def advertisement(): + copyright = "PaddleClas is powered by PaddlePaddle !" + info = "For more info please go to the following website." + website = "https://github.com/PaddlePaddle/PaddleClas" + AD_LEN = 55 + + _logger.info("\n{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n{7}\n".format( + "=" * (AD_LEN + 4), + "=={}==".format(copyright.center(AD_LEN)), + "=" * (AD_LEN + 4), + "=={}==".format(' ' * AD_LEN), + "=={}==".format(info.center(AD_LEN)), + "=={}==".format(' ' * AD_LEN), + "=={}==".format(website.center(AD_LEN)), + "=" * (AD_LEN + 4), )) diff --git a/tools/train.py b/tools/train.py index 83790a87..1f22d6b3 100644 --- a/tools/train.py +++ b/tools/train.py @@ -11,24 +11,19 @@ # 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. - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - import argparse import os import paddle.fluid as fluid - import program +from paddle.fluid.incubate.fleet.base import role_maker +from paddle.fluid.incubate.fleet.collective import fleet from ppcls.data import Reader +from ppcls.utils import logger from ppcls.utils.config import get_config -from ppcls.utils.save_load import init_model, save_model - -from paddle.fluid.incubate.fleet.collective import fleet -from paddle.fluid.incubate.fleet.base import role_maker +from ppcls.utils.save_load import init_model +from ppcls.utils.save_load import save_model def parse_args(): @@ -109,3 +104,4 @@ def main(args): if __name__ == '__main__': args = parse_args() main(args) + logger.advertisement() -- GitLab