From 618a063ddcd39ce66a7ac0c345de9d08f3bb1308 Mon Sep 17 00:00:00 2001 From: Yanhong Zeng Date: Wed, 2 Nov 2022 10:16:56 +0800 Subject: [PATCH] [Docs] Fix docstring and documentation used for hub.get_model (#659) * fix docstring and documentation used for hub.get_model * fix config name in test_hub * fix docstring mentioned faster-rcnn in utils --- docs/zh_cn/tutorials/config.md | 8 ++++---- mmengine/config/utils.py | 2 +- mmengine/hub/hub.py | 4 ++-- tests/test_hub/test_hub.py | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/zh_cn/tutorials/config.md b/docs/zh_cn/tutorials/config.md index 10a5cdd1..70617ac1 100644 --- a/docs/zh_cn/tutorials/config.md +++ b/docs/zh_cn/tutorials/config.md @@ -533,7 +533,7 @@ print(custom_optim) configs/_base_/schedules/schedule_1x.py configs/_base_/datasets.coco_instance.py configs/_base_/default_runtime.py -configs/_base_/models/faster_rcnn_r50_fpn.py +configs/_base_/models/faster-rcnn_r50_fpn.py ``` 如果没有配置文件跨项目继承的功能,我们就需要把 MMDetection 的配置文件拷贝到当前项目,而我们现在只需要安装 MMDetection @@ -546,7 +546,7 @@ _base_ = [ 'mmdet::_base_/schedules/schedule_1x.py', 'mmdet::_base_/datasets/coco_instance.py', 'mmdet::_base_/default_runtime.py', - 'mmdet::_base_/models/faster_rcnn_r50_fpn.py', + 'mmdet::_base_/models/faster-rcnn_r50_fpn.py', ] ``` @@ -575,7 +575,7 @@ MMEngine 还提供了 `get_config` 和 `get_model` 两个接口,支持对符 from mmengine.hub import get_model model = get_model( - 'mmdet::faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py', pretrained=True) + 'mmdet::faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py', pretrained=True) print(type(model)) ``` @@ -592,7 +592,7 @@ http loads checkpoint from path: https://download.openmmlab.com/mmdetection/v2.0 from mmengine.hub import get_config cfg = get_config( - 'mmdet::faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py', pretrained=True) + 'mmdet::faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py', pretrained=True) print(cfg.model_path) ``` diff --git a/mmengine/config/utils.py b/mmengine/config/utils.py index 7eec2c65..529a09a4 100644 --- a/mmengine/config/utils.py +++ b/mmengine/config/utils.py @@ -106,7 +106,7 @@ def _get_package_and_cfg_path(cfg_path: str) -> Tuple[str, str]: raise ValueError( '`_get_package_and_cfg_path` is used for get external package, ' 'please specify the package name and relative config path, just ' - 'like `mmdet::faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py`') + 'like `mmdet::faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py`') package_cfg = cfg_path.split('::') if len(package_cfg) > 2: raise ValueError('`::` should only be used to separate package and ' diff --git a/mmengine/hub/hub.py b/mmengine/hub/hub.py index 062c5423..b7b0d4ad 100644 --- a/mmengine/hub/hub.py +++ b/mmengine/hub/hub.py @@ -21,9 +21,9 @@ def get_config(cfg_path: str, pretrained: bool = False) -> Config: by ``cfg.model_path``. Defaults to False. Examples: - >>> cfg = get_config('mmdet::faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py', pretrained=True) + >>> cfg = get_config('mmdet::faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py', pretrained=True) >>> # Equivalent to - >>> # cfg = Config.fromfile('/path/to/faster_rcnn_r50_fpn_1x_coco.py') + >>> # cfg = Config.fromfile('/path/to/faster-rcnn_r50_fpn_1x_coco.py') >>> cfg.model_path https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth diff --git a/tests/test_hub/test_hub.py b/tests/test_hub/test_hub.py index 940fd8fc..bc97bae7 100644 --- a/tests/test_hub/test_hub.py +++ b/tests/test_hub/test_hub.py @@ -17,23 +17,23 @@ data_path = osp.join(osp.dirname(osp.dirname(__file__)), 'data/') reason='mmdet and mmpose should be installed') def test_get_config(): # Test load base config. - base_cfg = get_config('mmdet::_base_/models/faster_rcnn_r50_fpn.py') + base_cfg = get_config('mmdet::_base_/models/faster-rcnn_r50_fpn.py') package_path = get_installed_path('mmdet') test_base_cfg = Config.fromfile( osp.join(package_path, '.mim', - 'configs/_base_/models/faster_rcnn_r50_fpn.py')) + 'configs/_base_/models/faster-rcnn_r50_fpn.py')) assert test_base_cfg._cfg_dict == base_cfg._cfg_dict # Test load faster_rcnn config - cfg = get_config('mmdet::faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py') + cfg = get_config('mmdet::faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py') test_cfg = Config.fromfile( osp.join(package_path, '.mim', - 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py')) + 'configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py')) assert cfg._cfg_dict == test_cfg._cfg_dict # Test pretrained cfg = get_config( - 'mmdet::faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py', pretrained=True) + 'mmdet::faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py', pretrained=True) assert cfg.model_path == 'https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth' # noqa E301 # Test load mmpose