#!/usr/bin/env python
"""
make_objects365_palette.py
───────────────────────────────────────────────────────────
Objects365 전용 365-color 팔레트를 fire-config와 똑같은
( R, G, B ) 튜플 배열 형식으로 텍스트 파일로 저장한다.
"""

from importlib.util import spec_from_file_location, module_from_spec
from pathlib import Path

# 1) 팔레트 정의가 들어 있는 모듈 위치
CLASSES_PY = Path("/data/ltb/mmyolo/objects365_classes.py")

# 2) 모듈 동적 import
spec = spec_from_file_location("obj365", CLASSES_PY)
obj365 = module_from_spec(spec)
spec.loader.exec_module(obj365)

# 3) 팔레트 추출 (길이 = 365)
palette = obj365.PALETTE
assert len(palette) == 365, f"Palette length is {len(palette)}, expected 365."

# 4) 저장 경로
out_path = Path("objects365_palette.txt")

# 5) 파일로 저장 – fire-config와 동일 포맷
with out_path.open("w", encoding="utf-8") as fp:
    fp.write("PALETTE = [\n")
    for tup in palette:
        fp.write(f"    {tup},\n")
    fp.write("]\n")

print(f"[✓] 365-color palette saved to {out_path.resolve()}")
