Implementation:Obss Sahi Download Mmdet Config
| Knowledge Sources | |
|---|---|
| Domains | Object_Detection, Model_Setup |
| Last Updated | 2026-02-08 12:00 GMT |
Overview
Utility functions for downloading MMDetection model weights, configuration files, and resolving nested config inheritance hierarchies.
Description
The sahi.utils.mmdet module provides helper functions for downloading and setting up MMDetection models. MmdetTestConstants defines URLs and local paths for standard test models (Cascade Mask R-CNN, RetinaNet, YOLOX-Tiny). Dedicated download functions handle each model variant. The download_mmdet_config function is the most complex: it downloads a primary config file from the MMDetection GitHub repository, recursively fetches all inherited _base_ configs, and merges them into a single flat config file using mmengine.Config.
Usage
Use these utilities when setting up MMDetection models for use with SAHI. The download_mmdet_config function is particularly useful for obtaining ready-to-use config files without cloning the entire MMDetection repository.
Code Reference
Source Location
- Repository: Obss_Sahi
- File: sahi/utils/mmdet.py
- Lines: 1-189
Signature
def mmdet_version_as_integer() -> int: ...
class MmdetTestConstants:
MMDET_CASCADEMASKRCNN_MODEL_URL: str
MMDET_CASCADEMASKRCNN_MODEL_PATH: str
MMDET_RETINANET_MODEL_URL: str
MMDET_RETINANET_MODEL_PATH: str
MMDET_YOLOX_TINY_MODEL_URL: str
MMDET_YOLOX_TINY_MODEL_PATH: str
MMDET_CASCADEMASKRCNN_CONFIG_PATH: str
MMDET_RETINANET_CONFIG_PATH: str
MMDET_YOLOX_TINY_CONFIG_PATH: str
def download_mmdet_cascade_mask_rcnn_model(destination_path: str | None = None) -> None: ...
def download_mmdet_retinanet_model(destination_path: str | None = None) -> None: ...
def download_mmdet_yolox_tiny_model(destination_path: str | None = None) -> None: ...
def download_mmdet_config(
model_name: str = "cascade_rcnn",
config_file_name: str = "cascade_mask_rcnn_r50_fpn_1x_coco.py",
verbose: bool = True,
) -> str:
"""Downloads and merges MMDetection config files.
Returns:
(str) abs path of the downloaded config file.
"""
Import
from sahi.utils.mmdet import (
download_mmdet_config,
download_mmdet_cascade_mask_rcnn_model,
MmdetTestConstants,
)
I/O Contract
Inputs (download_mmdet_config)
| Name | Type | Required | Description |
|---|---|---|---|
| model_name | str | No (default "cascade_rcnn") | MMDetection model family name |
| config_file_name | str | No | Main config filename to download |
| verbose | bool | No (default True) | Print save path on completion |
Outputs
| Name | Type | Description |
|---|---|---|
| config_path | str | Absolute path to the merged config file |
| Config file | File | Single merged MMDetection config at mmdet_configs/{version}/{model}/ |
Usage Examples
Download MMDetection Config
from sahi.utils.mmdet import download_mmdet_config
# Download and merge Cascade Mask R-CNN config
config_path = download_mmdet_config(
model_name="cascade_rcnn",
config_file_name="cascade_mask_rcnn_r50_fpn_1x_coco.py",
)
print(f"Config saved to: {config_path}")
Download Model Weights
from sahi.utils.mmdet import download_mmdet_retinanet_model
# Download RetinaNet weights to default path
download_mmdet_retinanet_model()
# Or specify custom destination
download_mmdet_retinanet_model(destination_path="/models/retinanet.pth")