From 6887a320a56ad8dd59f9b6cc377e988f0774ff94 Mon Sep 17 00:00:00 2001 From: "shaohua.zhang" Date: Tue, 25 Aug 2020 15:42:51 +0800 Subject: [PATCH 1/8] Delete duplicate function Delete duplicate function: create_multi_devices_program, it is same as program.create_multi_devices_program --- ppocr/utils/utility.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/ppocr/utils/utility.py b/ppocr/utils/utility.py index e27dd1d87..2cf3c8f5c 100755 --- a/ppocr/utils/utility.py +++ b/ppocr/utils/utility.py @@ -90,15 +90,3 @@ def check_and_read_gif(img_path): return imgvalue, True return None, False - -def create_multi_devices_program(program, loss_var_name): - build_strategy = fluid.BuildStrategy() - build_strategy.memory_optimize = False - build_strategy.enable_inplace = True - exec_strategy = fluid.ExecutionStrategy() - exec_strategy.num_iteration_per_drop_scope = 1 - compile_program = fluid.CompiledProgram(program).with_data_parallel( - loss_name=loss_var_name, - build_strategy=build_strategy, - exec_strategy=exec_strategy) - return compile_program From 935966a2c2dbf8c07b36de0208064e3c995969cb Mon Sep 17 00:00:00 2001 From: "shaohua.zhang" Date: Thu, 27 Aug 2020 14:17:43 +0800 Subject: [PATCH 2/8] fix the path it is only a example, the probleams appear the files in the config folder.The path dose not fix for the windows system ,at the same ,we should use the relativte path instead of absoulate path. --- configs/rec/rec_icdar15_train.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/rec/rec_icdar15_train.yml b/configs/rec/rec_icdar15_train.yml index 98a38e747..59c460d52 100755 --- a/configs/rec/rec_icdar15_train.yml +++ b/configs/rec/rec_icdar15_train.yml @@ -15,8 +15,8 @@ Global: loss_type: ctc distort: true debug: false - reader_yml: ./configs/rec/rec_icdar15_reader.yml - pretrain_weights: ./pretrain_models/rec_mv3_none_bilstm_ctc/best_accuracy + reader_yml: ../configs/rec/rec_icdar15_reader.yml + pretrain_weights: ../pretrain_models/rec_mv3_none_bilstm_ctc/best_accuracy checkpoints: save_inference_dir: infer_img: From 7bfbbe47bc6d3f8d92628aa4eaa8de8a4cf40563 Mon Sep 17 00:00:00 2001 From: "shaohua.zhang" Date: Thu, 27 Aug 2020 14:27:19 +0800 Subject: [PATCH 3/8] Revert "fix the path " --- configs/rec/rec_icdar15_train.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/rec/rec_icdar15_train.yml b/configs/rec/rec_icdar15_train.yml index 59c460d52..98a38e747 100755 --- a/configs/rec/rec_icdar15_train.yml +++ b/configs/rec/rec_icdar15_train.yml @@ -15,8 +15,8 @@ Global: loss_type: ctc distort: true debug: false - reader_yml: ../configs/rec/rec_icdar15_reader.yml - pretrain_weights: ../pretrain_models/rec_mv3_none_bilstm_ctc/best_accuracy + reader_yml: ./configs/rec/rec_icdar15_reader.yml + pretrain_weights: ./pretrain_models/rec_mv3_none_bilstm_ctc/best_accuracy checkpoints: save_inference_dir: infer_img: From a7e915bf7bb06074e97a7ef6d7057d0c13bd6670 Mon Sep 17 00:00:00 2001 From: littletomatodonkey Date: Tue, 15 Sep 2020 14:12:44 +0000 Subject: [PATCH 4/8] fix mklnn memory leak --- deploy/cpp_infer/src/ocr_det.cpp | 1 + deploy/cpp_infer/src/ocr_rec.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/deploy/cpp_infer/src/ocr_det.cpp b/deploy/cpp_infer/src/ocr_det.cpp index 56fbace8c..a935003bb 100644 --- a/deploy/cpp_infer/src/ocr_det.cpp +++ b/deploy/cpp_infer/src/ocr_det.cpp @@ -26,6 +26,7 @@ void DBDetector::LoadModel(const std::string &model_dir) { config.DisableGpu(); if (this->use_mkldnn_) { config.EnableMKLDNN(); + config.SetMkldnnCacheCapacity(10); } config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_); } diff --git a/deploy/cpp_infer/src/ocr_rec.cpp b/deploy/cpp_infer/src/ocr_rec.cpp index a3486db46..9d71d8c45 100644 --- a/deploy/cpp_infer/src/ocr_rec.cpp +++ b/deploy/cpp_infer/src/ocr_rec.cpp @@ -126,6 +126,7 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) { config.DisableGpu(); if (this->use_mkldnn_) { config.EnableMKLDNN(); + config.SetMkldnnCacheCapacity(10); } config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_); } From 74f983d1820d2398ef649c023740e2bb58ab87dd Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 15 Sep 2020 22:23:25 +0800 Subject: [PATCH 5/8] mv docker to deploy/docker --- {docker => deploy/docker}/hubserving/README.md | 2 +- {docker => deploy/docker}/hubserving/README_cn.md | 2 +- {docker => deploy/docker}/hubserving/cpu/Dockerfile | 0 {docker => deploy/docker}/hubserving/gpu/Dockerfile | 0 {docker => deploy/docker}/hubserving/sample_request.txt | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename {docker => deploy/docker}/hubserving/README.md (99%) rename {docker => deploy/docker}/hubserving/README_cn.md (99%) rename {docker => deploy/docker}/hubserving/cpu/Dockerfile (100%) rename {docker => deploy/docker}/hubserving/gpu/Dockerfile (100%) rename {docker => deploy/docker}/hubserving/sample_request.txt (100%) diff --git a/docker/hubserving/README.md b/deploy/docker/hubserving/README.md similarity index 99% rename from docker/hubserving/README.md rename to deploy/docker/hubserving/README.md index 71e2377dc..62381073d 100644 --- a/docker/hubserving/README.md +++ b/deploy/docker/hubserving/README.md @@ -20,7 +20,7 @@ git clone https://github.com/PaddlePaddle/PaddleOCR.git ``` b. Goto Dockerfile directory(ps:Need to distinguish between cpu and gpu version, the following takes cpu as an example, gpu version needs to replace the keyword) ``` -cd docker/cpu +cd deploy/docker/cpu ``` c. Build image ``` diff --git a/docker/hubserving/README_cn.md b/deploy/docker/hubserving/README_cn.md similarity index 99% rename from docker/hubserving/README_cn.md rename to deploy/docker/hubserving/README_cn.md index 9b9e5f50f..f117a0ab4 100644 --- a/docker/hubserving/README_cn.md +++ b/deploy/docker/hubserving/README_cn.md @@ -20,7 +20,7 @@ git clone https://github.com/PaddlePaddle/PaddleOCR.git ``` b.切换至Dockerfile目录(注:需要区分cpu或gpu版本,下文以cpu为例,gpu版本需要替换一下关键字即可) ``` -cd docker/cpu +cd deploy/docker/cpu ``` c.生成镜像 ``` diff --git a/docker/hubserving/cpu/Dockerfile b/deploy/docker/hubserving/cpu/Dockerfile similarity index 100% rename from docker/hubserving/cpu/Dockerfile rename to deploy/docker/hubserving/cpu/Dockerfile diff --git a/docker/hubserving/gpu/Dockerfile b/deploy/docker/hubserving/gpu/Dockerfile similarity index 100% rename from docker/hubserving/gpu/Dockerfile rename to deploy/docker/hubserving/gpu/Dockerfile diff --git a/docker/hubserving/sample_request.txt b/deploy/docker/hubserving/sample_request.txt similarity index 100% rename from docker/hubserving/sample_request.txt rename to deploy/docker/hubserving/sample_request.txt From f78678dd66a798d78a8c9cb07af3c58dee7609b0 Mon Sep 17 00:00:00 2001 From: littletomatodonkey Date: Tue, 15 Sep 2020 14:23:41 +0000 Subject: [PATCH 6/8] fix py infer --- tools/infer/utility.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/infer/utility.py b/tools/infer/utility.py index 8d66f8671..1d07f62f2 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -101,6 +101,7 @@ def create_predictor(args, mode): config.disable_gpu() config.set_cpu_math_library_num_threads(6) if args.enable_mkldnn: + config.set_mkldnn_cache_capacity(10) config.enable_mkldnn() #config.enable_memory_optim() From 5858441b3d95c15ba040c061ae968f1e19f879b7 Mon Sep 17 00:00:00 2001 From: littletomatodonkey Date: Tue, 15 Sep 2020 15:52:52 +0000 Subject: [PATCH 7/8] add notes --- deploy/cpp_infer/src/ocr_det.cpp | 1 + deploy/cpp_infer/src/ocr_rec.cpp | 1 + deploy/cpp_infer/tools/config.txt | 2 +- tools/infer/utility.py | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/deploy/cpp_infer/src/ocr_det.cpp b/deploy/cpp_infer/src/ocr_det.cpp index a935003bb..bf94abce2 100644 --- a/deploy/cpp_infer/src/ocr_det.cpp +++ b/deploy/cpp_infer/src/ocr_det.cpp @@ -26,6 +26,7 @@ void DBDetector::LoadModel(const std::string &model_dir) { config.DisableGpu(); if (this->use_mkldnn_) { config.EnableMKLDNN(); + // cache 10 different shapes for mkldnn to avoid memory leak config.SetMkldnnCacheCapacity(10); } config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_); diff --git a/deploy/cpp_infer/src/ocr_rec.cpp b/deploy/cpp_infer/src/ocr_rec.cpp index 9d71d8c45..b997d8291 100644 --- a/deploy/cpp_infer/src/ocr_rec.cpp +++ b/deploy/cpp_infer/src/ocr_rec.cpp @@ -126,6 +126,7 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) { config.DisableGpu(); if (this->use_mkldnn_) { config.EnableMKLDNN(); + // cache 10 different shapes for mkldnn to avoid memory leak config.SetMkldnnCacheCapacity(10); } config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_); diff --git a/deploy/cpp_infer/tools/config.txt b/deploy/cpp_infer/tools/config.txt index 40beea3a2..6c53f29ee 100644 --- a/deploy/cpp_infer/tools/config.txt +++ b/deploy/cpp_infer/tools/config.txt @@ -3,7 +3,7 @@ use_gpu 0 gpu_id 0 gpu_mem 4000 cpu_math_library_num_threads 10 -use_mkldnn 0 +use_mkldnn 1 use_zero_copy_run 1 # det config diff --git a/tools/infer/utility.py b/tools/infer/utility.py index 1d07f62f2..3e1f07b8a 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -101,6 +101,7 @@ def create_predictor(args, mode): config.disable_gpu() config.set_cpu_math_library_num_threads(6) if args.enable_mkldnn: + # cache 10 different shapes for mkldnn to avoid memory leak config.set_mkldnn_cache_capacity(10) config.enable_mkldnn() From 2aa0c8eb2d8baa7567aadba797315d4203a0d2ac Mon Sep 17 00:00:00 2001 From: littletomatodonkey Date: Tue, 15 Sep 2020 16:04:06 +0000 Subject: [PATCH 8/8] remove re-init --- tools/infer/predict_system.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tools/infer/predict_system.py b/tools/infer/predict_system.py index 647a76b20..ff5d53e94 100755 --- a/tools/infer/predict_system.py +++ b/tools/infer/predict_system.py @@ -122,7 +122,6 @@ def main(args): image_file_list = get_image_file_list(args.image_dir) text_sys = TextSystem(args) is_visualize = True - tackle_img_num = 0 for image_file in image_file_list: img, flag = check_and_read_gif(image_file) if not flag: @@ -131,9 +130,6 @@ def main(args): logger.info("error in loading image:{}".format(image_file)) continue starttime = time.time() - tackle_img_num += 1 - if not args.use_gpu and args.enable_mkldnn and tackle_img_num % 30 == 0: - text_sys = TextSystem(args) dt_boxes, rec_res = text_sys(img) elapse = time.time() - starttime print("Predict time of %s: %.3fs" % (image_file, elapse)) @@ -153,11 +149,7 @@ def main(args): scores = [rec_res[i][1] for i in range(len(rec_res))] draw_img = draw_ocr( - image, - boxes, - txts, - scores, - drop_score=drop_score) + image, boxes, txts, scores, drop_score=drop_score) draw_img_save = "./inference_results/" if not os.path.exists(draw_img_save): os.makedirs(draw_img_save)