mirror of
https://github.com/PaddlePaddle/PaddleOCR.git
synced 2025-06-03 21:53:39 +08:00
Merge pull request #721 from littletomatodonkey/fix_mkldnn
fix mklnn memory leak
This commit is contained in:
commit
a88764eae4
@ -26,6 +26,8 @@ void DBDetector::LoadModel(const std::string &model_dir) {
|
|||||||
config.DisableGpu();
|
config.DisableGpu();
|
||||||
if (this->use_mkldnn_) {
|
if (this->use_mkldnn_) {
|
||||||
config.EnableMKLDNN();
|
config.EnableMKLDNN();
|
||||||
|
// cache 10 different shapes for mkldnn to avoid memory leak
|
||||||
|
config.SetMkldnnCacheCapacity(10);
|
||||||
}
|
}
|
||||||
config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_);
|
config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_);
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,8 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
|
|||||||
config.DisableGpu();
|
config.DisableGpu();
|
||||||
if (this->use_mkldnn_) {
|
if (this->use_mkldnn_) {
|
||||||
config.EnableMKLDNN();
|
config.EnableMKLDNN();
|
||||||
|
// cache 10 different shapes for mkldnn to avoid memory leak
|
||||||
|
config.SetMkldnnCacheCapacity(10);
|
||||||
}
|
}
|
||||||
config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_);
|
config.SetCpuMathLibraryNumThreads(this->cpu_math_library_num_threads_);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use_gpu 0
|
|||||||
gpu_id 0
|
gpu_id 0
|
||||||
gpu_mem 4000
|
gpu_mem 4000
|
||||||
cpu_math_library_num_threads 10
|
cpu_math_library_num_threads 10
|
||||||
use_mkldnn 0
|
use_mkldnn 1
|
||||||
use_zero_copy_run 1
|
use_zero_copy_run 1
|
||||||
|
|
||||||
# det config
|
# det config
|
||||||
|
@ -122,7 +122,6 @@ def main(args):
|
|||||||
image_file_list = get_image_file_list(args.image_dir)
|
image_file_list = get_image_file_list(args.image_dir)
|
||||||
text_sys = TextSystem(args)
|
text_sys = TextSystem(args)
|
||||||
is_visualize = True
|
is_visualize = True
|
||||||
tackle_img_num = 0
|
|
||||||
for image_file in image_file_list:
|
for image_file in image_file_list:
|
||||||
img, flag = check_and_read_gif(image_file)
|
img, flag = check_and_read_gif(image_file)
|
||||||
if not flag:
|
if not flag:
|
||||||
@ -131,9 +130,6 @@ def main(args):
|
|||||||
logger.info("error in loading image:{}".format(image_file))
|
logger.info("error in loading image:{}".format(image_file))
|
||||||
continue
|
continue
|
||||||
starttime = time.time()
|
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)
|
dt_boxes, rec_res = text_sys(img)
|
||||||
elapse = time.time() - starttime
|
elapse = time.time() - starttime
|
||||||
print("Predict time of %s: %.3fs" % (image_file, elapse))
|
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))]
|
scores = [rec_res[i][1] for i in range(len(rec_res))]
|
||||||
|
|
||||||
draw_img = draw_ocr(
|
draw_img = draw_ocr(
|
||||||
image,
|
image, boxes, txts, scores, drop_score=drop_score)
|
||||||
boxes,
|
|
||||||
txts,
|
|
||||||
scores,
|
|
||||||
drop_score=drop_score)
|
|
||||||
draw_img_save = "./inference_results/"
|
draw_img_save = "./inference_results/"
|
||||||
if not os.path.exists(draw_img_save):
|
if not os.path.exists(draw_img_save):
|
||||||
os.makedirs(draw_img_save)
|
os.makedirs(draw_img_save)
|
||||||
|
@ -101,6 +101,8 @@ def create_predictor(args, mode):
|
|||||||
config.disable_gpu()
|
config.disable_gpu()
|
||||||
config.set_cpu_math_library_num_threads(6)
|
config.set_cpu_math_library_num_threads(6)
|
||||||
if args.enable_mkldnn:
|
if args.enable_mkldnn:
|
||||||
|
# cache 10 different shapes for mkldnn to avoid memory leak
|
||||||
|
config.set_mkldnn_cache_capacity(10)
|
||||||
config.enable_mkldnn()
|
config.enable_mkldnn()
|
||||||
|
|
||||||
#config.enable_memory_optim()
|
#config.enable_memory_optim()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user