From c5f00a8d7091b46b0ecd175f722d98ea8bea485e Mon Sep 17 00:00:00 2001 From: HaodongDuan Date: Fri, 16 Oct 2020 17:35:47 +0800 Subject: [PATCH 1/4] resolve comments --- tools/data/hvu/generate_sub_file_list.py | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tools/data/hvu/generate_sub_file_list.py diff --git a/tools/data/hvu/generate_sub_file_list.py b/tools/data/hvu/generate_sub_file_list.py new file mode 100644 index 0000000000..77c7bed651 --- /dev/null +++ b/tools/data/hvu/generate_sub_file_list.py @@ -0,0 +1,49 @@ +import argparse +import os.path as osp + +import mmcv + + +def main(annotation_file, category): + assert category in [ + 'action', 'attribute', 'concept', 'event', 'object', 'scene' + ] + + data = mmcv.load(annotation_file) + basename = osp.basename(annotation_file) + dirname = osp.dirname(annotation_file) + basename = basename.replace('hvu', f'hvu_{category}') + + target_file = osp.join(dirname, basename) + + def parse_item(item, category): + label = item['label'] + if category in label: + item['label'] = label[category] + return item + else: + return None + + result = [] + for item in data: + label = item['label'] + if category in label: + item['label'] = label[category] + result.append(item) + + mmcv.dump(data, target_file) + + +if __name__ == '__main__': + description = 'Helper script for generating HVU per-category file list.' + p = argparse.ArgumentParser(description=description) + p.add_argument( + 'annotation_file', + type=str, + help=('The annotation file which contains tags of all categories.')) + p.add_argument( + 'category', + type=str, + choices=['action', 'attribute', 'concept', 'event', 'object', 'scene'], + help='The tag category that you want to generate file list for.') + main(**vars(p.parse_args())) From 05575c18bf7dbba7e6e9f9a0f1c4f973668d2c44 Mon Sep 17 00:00:00 2001 From: HaodongDuan Date: Fri, 16 Oct 2020 17:37:19 +0800 Subject: [PATCH 2/4] update changelog --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index d0fe20a249..3cff48664d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,7 @@ **Improvements** - Set default values of 'average_clips' in each config file so that there is no need to set it explicitly during testing in most cases ([#232](https://github.com/open-mmlab/mmaction2/pull/232)) +- Extend HVU datatools to generate individual file list for each tag category ([#258](https://github.com/open-mmlab/mmaction2/pull/258)) **Bug Fixes** - Fix the potential bug for default value in dataset_setting ([#245](https://github.com/open-mmlab/mmaction2/pull/245)) From 5ec9686e3b800296abd598adf0f4faef7ef60df3 Mon Sep 17 00:00:00 2001 From: HaodongDuan Date: Tue, 3 Nov 2020 19:54:07 +0800 Subject: [PATCH 3/4] remove redundant code --- tools/test.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/test.py b/tools/test.py index 3b3364dacb..863c5c5d80 100644 --- a/tools/test.py +++ b/tools/test.py @@ -1,9 +1,7 @@ import argparse import os -import os.path as osp import warnings -import mmcv import torch from mmcv import Config, DictAction from mmcv.cnn import fuse_conv_bn @@ -146,8 +144,6 @@ def main(): distributed = True init_dist(args.launcher, **cfg.dist_params) - # create work_dir - mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir)) # build the dataloader dataset = build_dataset(cfg.data.test, dict(test_mode=True)) dataloader_setting = dict( From 6ff2f73c3897fd968f48999df73e7f8a790888f7 Mon Sep 17 00:00:00 2001 From: HaodongDuan Date: Wed, 4 Nov 2020 15:29:39 +0800 Subject: [PATCH 4/4] update --- tools/test.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/test.py b/tools/test.py index 863c5c5d80..9f15ca8cb9 100644 --- a/tools/test.py +++ b/tools/test.py @@ -1,10 +1,13 @@ import argparse import os +import os.path as osp import warnings +import mmcv import torch from mmcv import Config, DictAction from mmcv.cnn import fuse_conv_bn +from mmcv.fileio.io import file_handlers from mmcv.parallel import MMDataParallel, MMDistributedDataParallel from mmcv.runner import get_dist_info, init_dist, load_checkpoint from mmcv.runner.fp16_utils import wrap_fp16_model @@ -90,17 +93,6 @@ def parse_args(): return args -def merge_configs(cfg1, cfg2): - # Merge cfg2 into cfg1 - # Overwrite cfg1 if repeated, ignore if value is None. - cfg1 = {} if cfg1 is None else cfg1.copy() - cfg2 = {} if cfg2 is None else cfg2 - for k, v in cfg2.items(): - if v: - cfg1[k] = v - return cfg1 - - def main(): args = parse_args() @@ -111,19 +103,27 @@ def main(): # Load output_config from cfg output_config = cfg.get('output_config', {}) # Overwrite output_config from args.out - output_config = merge_configs(output_config, dict(out=args.out)) + output_config = Config._merge_a_into_b(dict(out=args.out), output_config) # Load eval_config from cfg eval_config = cfg.get('eval_config', {}) # Overwrite eval_config from args.eval - eval_config = merge_configs(eval_config, dict(metrics=args.eval)) + eval_config = Config._merge_a_into_b(dict(metrics=args.eval), eval_config) # Add options from args.eval_options - eval_config = merge_configs(eval_config, args.eval_options) + eval_config = Config._merge_a_into_b(args.eval_options, eval_config) assert output_config or eval_config, \ ('Please specify at least one operation (save or eval the ' 'results) with the argument "--out" or "--eval"') + if output_config: + out = output_config['out'] + # make sure the dirname of the output path exists + mmcv.mkdir_or_exist(osp.dirname(out)) + _, suffix = osp.splitext(out) + assert suffix in file_handlers, \ + 'The format of the output file should be json, pickle or yaml' + # set cudnn benchmark if cfg.get('cudnn_benchmark', False): torch.backends.cudnn.benchmark = True