From 1192c2976e4bdd37153e955b9bc428bf39e0011a Mon Sep 17 00:00:00 2001 From: huangjun12 <2399845970@qq.com> Date: Sun, 9 Feb 2020 10:21:28 +0800 Subject: [PATCH] fix multiprocessing bug of bmn dynamic graph model (#4226) * fix bmn model implemented with dynamic graph mode * fix eval.py and README to increase the model usability --- dygraph/bmn/README.md | 8 +++++--- dygraph/bmn/eval.py | 22 +++++++++++----------- dygraph/bmn/reader.py | 5 ++++- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/dygraph/bmn/README.md b/dygraph/bmn/README.md index 1408cb5d..715c3cb7 100644 --- a/dygraph/bmn/README.md +++ b/dygraph/bmn/README.md @@ -21,6 +21,8 @@ BMN模型是百度自研,2019年ActivityNet夺冠方案,为视频动作定 BMN Overview

+BMN模型的静态图实现请参考[PaddleVideo](../../PaddleCV/PaddleVideo) + 动态图文档请参考[Dygraph](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/user_guides/howto/dygraph/DyGraph.html) @@ -81,7 +83,7 @@ BMN的训练数据采用ActivityNet1.3提供的数据集,我们提供了处理 python eval.py --weights=$PATH_TO_WEIGHTS -- 进行评估时,可修改脚本中的`weights`参数指定需要评估的权重,如果不设置,将使用默认参数文件checkpoint/bmn\_paddle\_dy\_final.pdparams。 +- 进行评估时,可修改命令行中的`weights`参数指定需要评估的权重,如果不设置,将使用默认参数文件checkpoint/bmn\_paddle\_dy\_final.pdparams。 - 上述程序会将运行结果保存在output/EVAL/BMN\_results文件夹下,测试结果保存在evaluate\_results/bmn\_results\_validation.json文件中。 @@ -94,9 +96,9 @@ BMN的训练数据采用ActivityNet1.3提供的数据集,我们提供了处理 - ActivityNet数据集的具体使用说明可以参考其[官方网站](http://activity-net.org) -- 下载指标评估代码,请从[ActivityNet Gitub repository](https://github.com/activitynet/ActivityNet.git)下载,将Evaluation文件夹拷贝至models/dygraph/bmn目录下。(注:若使用python3,print函数需要添加括号,请对Evaluation目录下的.py文件做相应修改。) +- 下载指标评估代码,请从[ActivityNet Gitub repository](https://github.com/activitynet/ActivityNet.git)下载,将Evaluation文件夹拷贝至models/dygraph/bmn目录下。(注:由于第三方评估代码不支持python3,此处建议使用python2进行评估;若使用python3,print函数需要添加括号,请对Evaluation目录下的.py文件做相应修改。) -- 请下载[activity\_net\_1\_3\_new.json](https://paddlemodels.bj.bcebos.com/video_detection/activity_net_1_3_new.json)文件,并将其放置在models/dygraph/bmn目录下,相较于原始的activity\_net.v1-3.min.json文件,我们过滤了其中一些失效的视频条目。 +- 请下载[activity\_net\_1\_3\_new.json](https://paddlemodels.bj.bcebos.com/video_detection/activity_net_1_3_new.json)文件,并将其放置在models/dygraph/bmn/Evaluation/data目录下,相较于原始的activity\_net.v1-3.min.json文件,我们过滤了其中一些失效的视频条目。 - 计算精度指标 diff --git a/dygraph/bmn/eval.py b/dygraph/bmn/eval.py index f9678069..2565fa76 100644 --- a/dygraph/bmn/eval.py +++ b/dygraph/bmn/eval.py @@ -44,10 +44,7 @@ def parse_args(): default='bmn.yaml', help='path to config file of model') parser.add_argument( - '--batch_size', - type=int, - default=None, - help='training batch size. None to use config file setting.') + '--batch_size', type=int, default=1, help='eval batch size.') parser.add_argument( '--use_gpu', type=ast.literal_eval, @@ -59,11 +56,6 @@ def parse_args(): default="checkpoint/bmn_paddle_dy_final", help='weight path, None to automatically download weights provided by Paddle.' ) - parser.add_argument( - '--save_dir', - type=str, - default="evaluate_results/", - help='output dir path, default to use ./evaluate_results/') parser.add_argument( '--log_interval', type=int, @@ -135,7 +127,12 @@ def test_bmn(args): os.makedirs(test_config.TEST.output_path) if not os.path.isdir(test_config.TEST.result_path): os.makedirs(test_config.TEST.result_path) - place = fluid.CUDAPlace(0) + + if not args.use_gpu: + place = fluid.CPUPlace() + else: + place = fluid.CUDAPlace(0) + with fluid.dygraph.guard(place): bmn = BMN(test_config) @@ -189,7 +186,10 @@ def test_bmn(args): aggr_pem_cls_loss += np.mean(pem_cls_loss.numpy()) aggr_batch_size += 1 - logger.info("Processing................ batch {}".format(batch_id)) + if batch_id % args.log_interval == 0: + logger.info("Processing................ batch {}".format( + batch_id)) + gen_props( pred_bm, pred_start, diff --git a/dygraph/bmn/reader.py b/dygraph/bmn/reader.py index c0877c59..11209fee 100644 --- a/dygraph/bmn/reader.py +++ b/dygraph/bmn/reader.py @@ -47,6 +47,8 @@ class BMNReader(): self.num_threads = 1 # set num_threads as 1 for test and infer def get_dataset_dict(self): + assert (os.path.exists(self.feat_path)), "Input feature path not exists" + assert (os.listdir(self.feat_path)), "Input feature file not exists" self.video_dict = {} if self.mode == "infer": annos = json.load(open(self.file_list)) @@ -265,7 +267,8 @@ class BMNReader(): tmp_list = video_list[i * file_num:] reader_lists[i] = tmp_list - queue = multiprocessing.Queue(queue_size) + manager = multiprocessing.Manager() + queue = manager.Queue(queue_size) p_list = [None] * len(reader_lists) for i in range(len(reader_lists)): reader_list = reader_lists[i] -- GitLab