diff --git a/ppocr/utils/utility.py b/ppocr/utils/utility.py index e27dd1d8738a25c6a6669b99ad2b6eed4a9f25d0..831b8eff97d4d3c158b0d5a6fc93d6153d000740 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 aff5fc7111a062c9b4346e9c2dcbc8f9225fe8da..a687bb6b33cca2e60e3b674c72a8765740286790 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 aebdc0761b7ec48f81143ecbb758ce0e4da2edf7..739925f8cfcb97ee584f1e00c081634ca131a0e7 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 4ac441a4edc60db87097d45a47e77ece4b55a8f7..79eb638dc2c61af3bd0c7a3c3c14b4a769650f45 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 29fc5b40a890cd6e8fa3ca7d3f0999835555d9bd..389453a4117550b00772970feb4262d14eab4256 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 cf0171b340f8cebb6251d2ef12efb14d3cdb709e..90344389b476a2747c9dfd7d90d5feb474626465 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()