From cf8530b9045e2b8d651268a042a9d0ff347e7db6 Mon Sep 17 00:00:00 2001 From: littletomatodonkey <2120160898@bit.edu.cn> Date: Wed, 11 Nov 2020 18:41:22 +0800 Subject: [PATCH] adapt codes to Paddle2.0-rc (#1153) --- ppocr/utils/utility.py | 8 ++++++++ tools/eval.py | 2 ++ tools/infer_cls.py | 2 ++ tools/infer_det.py | 2 ++ tools/infer_rec.py | 2 ++ tools/train.py | 2 ++ 6 files changed, 18 insertions(+) diff --git a/ppocr/utils/utility.py b/ppocr/utils/utility.py index e27dd1d8..831b8eff 100755 --- a/ppocr/utils/utility.py +++ b/ppocr/utils/utility.py @@ -16,6 +16,7 @@ import logging import os import imghdr import cv2 +import paddle from paddle import fluid @@ -102,3 +103,10 @@ def create_multi_devices_program(program, loss_var_name): build_strategy=build_strategy, exec_strategy=exec_strategy) return compile_program + + +def enable_static_mode(): + try: + paddle.enable_static() + except: + pass diff --git a/tools/eval.py b/tools/eval.py index aff5fc71..a687bb6b 100755 --- a/tools/eval.py +++ b/tools/eval.py @@ -39,6 +39,7 @@ set_paddle_flags( import program from paddle import fluid from ppocr.utils.utility import initial_logger +from ppocr.utils.utility import enable_static_mode logger = initial_logger() from ppocr.data.reader_main import reader_main from ppocr.utils.save_load import init_model @@ -95,4 +96,5 @@ def main(): if __name__ == '__main__': + enable_static_mode() main() diff --git a/tools/infer_cls.py b/tools/infer_cls.py index aebdc076..739925f8 100755 --- a/tools/infer_cls.py +++ b/tools/infer_cls.py @@ -41,6 +41,7 @@ set_paddle_flags( import tools.program as program from paddle import fluid from ppocr.utils.utility import initial_logger +from ppocr.utils.utility import enable_static_mode logger = initial_logger() from ppocr.data.reader_main import reader_main @@ -109,6 +110,7 @@ def main(): if __name__ == '__main__': + enable_static_mode() parser = program.ArgsParser() FLAGS = parser.parse_args() main() diff --git a/tools/infer_det.py b/tools/infer_det.py index 4ac441a4..79eb638d 100755 --- a/tools/infer_det.py +++ b/tools/infer_det.py @@ -49,6 +49,7 @@ import cv2 from ppocr.utils.utility import initial_logger logger = initial_logger() +from ppocr.utils.utility import enable_static_mode def draw_det_res(dt_boxes, config, img, img_name): @@ -162,6 +163,7 @@ def main(): if __name__ == '__main__': + enable_static_mode() parser = program.ArgsParser() FLAGS = parser.parse_args() main() diff --git a/tools/infer_rec.py b/tools/infer_rec.py index 29fc5b40..389453a4 100755 --- a/tools/infer_rec.py +++ b/tools/infer_rec.py @@ -41,6 +41,7 @@ import tools.program as program from paddle import fluid from ppocr.utils.utility import initial_logger logger = initial_logger() +from ppocr.utils.utility import enable_static_mode from ppocr.data.reader_main import reader_main from ppocr.utils.save_load import init_model from ppocr.utils.character import CharacterOps @@ -171,6 +172,7 @@ def main(): if __name__ == '__main__': + enable_static_mode() parser = program.ArgsParser() FLAGS = parser.parse_args() main() diff --git a/tools/train.py b/tools/train.py index cf0171b3..90344389 100755 --- a/tools/train.py +++ b/tools/train.py @@ -39,6 +39,7 @@ set_paddle_flags( import tools.program as program from paddle import fluid from ppocr.utils.utility import initial_logger +from ppocr.utils.utility import enable_static_mode logger = initial_logger() from ppocr.data.reader_main import reader_main from ppocr.utils.save_load import init_model @@ -126,6 +127,7 @@ def test_reader(): if __name__ == '__main__': + enable_static_mode() startup_program, train_program, place, config, train_alg_type = program.preprocess( ) main() -- GitLab