Skip to content

Commit

Permalink
[Docs] Fix docstring and documentation used for hub.get_model (#659)
Browse files Browse the repository at this point in the history
* fix docstring and documentation used for hub.get_model

* fix config name in test_hub

* fix docstring mentioned faster-rcnn in utils
  • Loading branch information
zengyh1900 committed Nov 2, 2022
1 parent 3aba989 commit 618a063
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions docs/zh_cn/tutorials/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
]
```

Expand Down Expand Up @@ -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))
```

Expand All @@ -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)

```
Expand Down
2 changes: 1 addition & 1 deletion mmengine/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down
4 changes: 2 additions & 2 deletions mmengine/hub/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/test_hub/test_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
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
Expand Down

0 comments on commit 618a063

Please sign in to comment.