Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Obss Sahi Export Cfg As Yaml

From Leeroopedia


Knowledge Sources
Domains Object_Detection, Configuration
Last Updated 2026-02-08 12:00 GMT

Overview

Utility function that serializes a Detectron2 configuration object to a YAML file for reuse and reproducibility.

Description

The export_cfg_as_yaml function in sahi.utils.detectron2 exports a Detectron2 CfgNode config object to YAML format. It creates the parent directory if needed and uses the built-in cfg.dump() method. The module also provides Detectron2TestConstants with predefined model zoo names for Faster R-CNN, RetinaNet, and Mask R-CNN.

Usage

Use this function when you need to persist a Detectron2 configuration to disk in YAML format, either for sharing, versioning, or later reloading the configuration without rebuilding it programmatically.

Code Reference

Source Location

Signature

class Detectron2TestConstants:
    FASTERCNN_MODEL_ZOO_NAME = "COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml"
    RETINANET_MODEL_ZOO_NAME = "COCO-Detection/retinanet_R_50_FPN_3x.yaml"
    MASKRCNN_MODEL_ZOO_NAME = "COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"

def export_cfg_as_yaml(cfg, export_path: str = "config.yaml") -> None:
    """Exports Detectron2 config object in yaml format.

    Args:
        cfg (detectron2.config.CfgNode): Detectron2 config object.
        export_path (str): Path to export the Detectron2 config.
    """

Import

from sahi.utils.detectron2 import export_cfg_as_yaml, Detectron2TestConstants

I/O Contract

Inputs

Name Type Required Description
cfg detectron2.config.CfgNode Yes Detectron2 configuration object
export_path str No (default "config.yaml") File path for the exported YAML

Outputs

Name Type Description
YAML file File Detectron2 config serialized as YAML at export_path

Usage Examples

Export Detectron2 Config

from detectron2.config import get_cfg
from detectron2 import model_zoo
from sahi.utils.detectron2 import export_cfg_as_yaml

# Build config
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml")

# Export to YAML
export_cfg_as_yaml(cfg, export_path="my_config.yaml")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment