Skip to content

YOLO

You only look once (YOLO) is a state-of-the-art, real-time object detection system. On a Titan X it processes images at 40-90 FPS and has a mAP on VOC 2007 of 78.6% and a mAP of 48.1% on COCO test-dev.

Categories

ONNX 변환 코드

(2026년 01월 19일 기준) Python 3.13.xx 까지 사용 가능.

패키지 설치:

pip3 install onnx onnxruntime onnxslim
  • onnx>=1.20.1
  • onnxruntime>=1.23.2
  • onnxslim>=0.1.82

변환하는 Python 코드:

"""YOLO 모델을 ONNX 형식으로 변환하는 스크립트."""

from pathlib import Path

from ultralytics import YOLO


def export_to_onnx(weights_path: str, opset: int = 12, simplify: bool = True, dynamic: bool = True) -> str:
    """
    YOLO 모델을 ONNX 형식으로 변환합니다.

    Args:
        weights_path: .pt 모델 파일 경로
        opset: ONNX opset 버전 (기본값: 12)
        simplify: onnx-simplifier 적용 여부 (기본값: True)
        dynamic: dynamic batch size 지원 여부 (기본값: True)

    Returns:
        변환된 ONNX 파일 경로
    """
    model = YOLO(weights_path)
    export_path = model.export(format="onnx", opset=opset, simplify=simplify, dynamic=dynamic)
    return export_path


def main():
    weights_dir = Path(__file__).parent / "weights"

    models = [
        weights_dir / "sh_weld_defect-20251113.pt",
        weights_dir / "sh_weld_zone-20251222.pt",
    ]

    for model_path in models:
        if not model_path.exists():
            print(f"모델 파일을 찾을 수 없습니다: {model_path}")
            continue

        print(f"변환 중: {model_path.name}")
        onnx_path = export_to_onnx(str(model_path))
        print(f"완료: {onnx_path}")


if __name__ == "__main__":
    main()

Troubleshooting

EarlyStopping: Training stopped early as no improvement observed in last N epochs

EarlyStopping: Training stopped early as no improvement observed in last 50 epochs.
Best results observed at epoch 9, best model saved as best.pt.

검증 성능(mAP50-95)이 9 에폭에서 최고치를 찍었음. 이후 9+50 = 59 에폭까지 50번 연속으로 그 기록을 갱신하지 못하자 자동으로 학습을 멈춘 것 (모든 에폭 다 안 채우고 조기 종료)

의도적으로 최대 에폭까지 다 보고 싶다면 patience=0 (비활성화) 또는 patience=100 이상으로 늘려서 재실행.

Documentation

You Only Look Once: Unified, Real-Time Object Detection
http://pjreddie.com/darknet/yolo/
https://github.com/pjreddie/darknet
1506.02640v4.pdf
YOLO9000 - Better, Faster, Stronger
https://arxiv.org/abs/1612.08242v1

Projects

PyLabel
컴퓨터 비전 라벨링 작업을 위한 Python 라이브러리. 핵심 기능은 서로 다른 형식(예: coco에서 yolo로) 간에 경계 상자 주석을 변환하는 것입니다.
https://github.com/pylabel-project/pylabel

See also

Favorite site