From d4dbec2928c18ecf47f7993e5436a90c9f4e08a7 Mon Sep 17 00:00:00 2001 From: Guanghua Yu <742925032@qq.com> Date: Wed, 23 Oct 2019 17:27:32 +0800 Subject: [PATCH] Fix pyramidbox load and flags (#3657) --- PaddleCV/face_detection/README_cn.md | 1 + PaddleCV/face_detection/widerface_eval.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/PaddleCV/face_detection/README_cn.md b/PaddleCV/face_detection/README_cn.md index 75df49f1..3329a914 100644 --- a/PaddleCV/face_detection/README_cn.md +++ b/PaddleCV/face_detection/README_cn.md @@ -111,6 +111,7 @@ python -u train.py --batch_size=16 --pretrained_model=vgg_ilsvrc_16_fc_reduced **注意**: - 本次开源模型中CPM模块与论文中有些许不同,相比论文中CPM模块训练和测试速度更快。 - Pyramid Anchors模块的body部分可以针对不同情况,进行相应的长宽设置来调参。同时face、head、body部分的loss对应的系数也可以通过调参优化。 + - 针对GPU资源有限时,可采取显存优化策略,`train.py` 与 `derface_eval.py` 已经加入部分显存优化FLAGS,详情更多内容请参考[API文档](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/flags/memory_cn.html#flags-fraction-of-gpu-memory-to-use) ### 模型评估 diff --git a/PaddleCV/face_detection/widerface_eval.py b/PaddleCV/face_detection/widerface_eval.py index 8ce7c3f3..27a0d285 100644 --- a/PaddleCV/face_detection/widerface_eval.py +++ b/PaddleCV/face_detection/widerface_eval.py @@ -22,6 +22,19 @@ import argparse import functools from PIL import Image +def set_paddle_flags(**kwargs): + for key, value in kwargs.items(): + if os.environ.get(key, None) is None: + os.environ[key] = str(value) + +# NOTE(paddle-dev): All of these flags should be +# set before `import paddle`. Otherwise, it would +# not take any effect. +set_paddle_flags( + FLAGS_eager_delete_tensor_gb=0, # enable GC to save memory +) + + import paddle.fluid as fluid import reader from pyramidbox import PyramidBox @@ -324,6 +337,7 @@ if __name__ == '__main__': is_infer=True) infer_program, nmsed_out = network.infer(main_program) fetches = [nmsed_out] + exe.run(startup_program) fluid.io.load_persistables( exe, args.model_dir, main_program=infer_program) # save model and program -- GitLab