콘텐츠로 이동

Getting started

1. 환경 설정


소스 코드를 준비합니다 (SaigeEdge submodule 포함).

git clone https://github.com/SAIGE-AI/safety-edge
cd safety-edge
git submodule update --init --recursive

Python 환경을 생성하고 dependencies를 설치합니다 (Python 3.10+).

conda create -n saige_safety_edge python=3.10
conda activate saige_safety_edge

pip install -r requirements/develop.txt

2. 사용


import cv2
from safety.engine.api import InferenceHandler

config = {
    "detection_checkpoint_path": "/path/to/det.saigeedge",
    "classification_checkpoint_path": "/path/to/cls.saigeedge",
    "password": None,                # DET / CLS 양쪽에 공용 적용. 평문이면 None.
    "camera_ids": [0],
}

err_code, err_msg, handler = InferenceHandler.build(config)

frame = cv2.imread("path/to/image.jpg", cv2.IMREAD_COLOR)
err_code, err_msg, results = handler.infer(
    images=[frame],
    camera_ids=[0],
    timestamps=[0],
)
for obj in results[0]["detected_objects"]:
    print(obj["object_class"], obj["events"], obj["alarms"])

각 기능에 대한 설명은 API Reference를 참고하세요.

3. 라이브러리 빌드


배포용으로 cythonize된 라이브러리를 빌드합니다. 예제에서는 deploy/ 폴더를 사용합니다.

pip install -r requirements/compile.txt
python setup.py build_ext --build-lib deploy -j `nproc`

빌드 시 tests, demo, scripts, configs, requirements 등 개발 전용 디렉토리는 자동으로 제외됩니다.

4. 데모 코드


python demo/inference.py