Instructions to use albitro/phoenix_detection with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ultralytics
How to use albitro/phoenix_detection with ultralytics:
# Couldn't find a valid YOLO version tag. # Replace XX with the correct version. from ultralytics import YOLOvXX model = YOLOvXX.from_pretrained("albitro/phoenix_detection") source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - Notebooks
- Google Colab
- Kaggle
File size: 4,977 Bytes
96f110e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #!/usr/bin/env python3
"""
์ ์ฒ๋ฆฌ ํ์ดํ๋ผ์ธ โ mode์ ๋ฐ๋ฅธ ์ฒ๋ฆฌ ์์. ROS ๋น์์กด.
๋
ธ๋ ์์ if๋ฌธ์ผ๋ก ํฉ์ด๋์ผ๋ฉด rclpy ์์ด๋ "mode๋ฅผ ๋ฐ๊ฟจ์ ๋ ์ ๋ง ๋ค๋ฅธ
์ฒ๋ฆฌ๊ฐ ๋๋๊ฐ"๋ฅผ ๊ฒ์ฆํ ์ ์์ต๋๋ค. ์ฌ๊ธฐ๋ก ๋นผ์ ๋
ธ๋ยท์คํ๋ผ์ธ ๋๊ตฌยทํ
์คํธ๊ฐ
**๊ฐ์ ์ฝ๋**๋ฅผ ์ฐ๊ฒ ํ์ต๋๋ค.
passthrough : ๋ฌด์ฒ๋ฆฌ (1๋จ๊ณ ๋ผ๋ โ QoSยทํค๋ ๋ฐฐ์ ๋ง ๊ฒ์ฆ)
clahe : ๊ฐ๋ง -> CLAHE (2๋จ๊ณ)
dehaze : ๊ฐ๋ง -> DCP (๊ธฐ์ฌ๋ ๋ถ๋ฆฌ์ฉ)
full : ๊ฐ๋ง -> DCP -> CLAHE (3๋จ๊ณ)
aod : ๊ฐ๋ง -> AOD-Net (DCP ๋์)
aod_full : ๊ฐ๋ง -> AOD-Net -> CLAHE
AOD-Net์ **๋ณ๋ ๋
ธ๋๊ฐ ์๋๋ผ mode๋ก** ๋ฃ์ ์ด์ ๋ HANDOVER 4-9. ๋น๊ต ๋๊ตฌยท
์ ๋ต ์ฑ์ ยท๋ถ์จ ์์กด ํ
์คํธยท๋ฐ์ดํฐ์
์์ฑ๊ธฐยท๋
ธ๋ ๋ฐฐ์ ์ด ์ ๋ถ ๊ทธ๋๋ก ์ฌ์ฌ์ฉ๋๊ณ ,
A/B๊ฐ ํ๋ผ๋ฏธํฐ ํ ์ค์ด ๋ฉ๋๋ค.
์์๊ฐ '๋ํค์ด์ฆ -> CLAHE'์ธ ์ด์ : ๋ํค์ด์ฆ๋ ๋ฌผ๋ฆฌ ๋ชจ๋ธ์ ์ญ์ฐ์ด๋ผ
**์
๋ ฅ์ด ์๋ณธ ๊ด์ธก๊ฐ I์ฌ์ผ** ์ฑ๋ฆฝํฉ๋๋ค. CLAHE๋ฅผ ๋จผ์ ๊ฑธ๋ฉด ํ์คํ ๊ทธ๋จ์ด
๋น์ ํ์ผ๋ก ๋ณํ๋ผ I = Jยทt + A(1-t) ๊ฐ์ ์ด ๊นจ์ง๋๋ค.
"""
from __future__ import annotations
import time
from .dehaze import ClaheEnhancer, DarkChannelDehazer, apply_gamma
MODES = ("passthrough", "clahe", "dehaze", "full", "aod", "aod_full")
# ๋ํค์ด์ฆ๊ฐ ๋๋ ๋ชจ๋์, ๊ทธ์ค AOD-Net์ ์ฐ๋ ๋ชจ๋.
DEHAZE_MODES = ("dehaze", "full", "aod", "aod_full")
AOD_MODES = ("aod", "aod_full")
CLAHE_MODES = ("clahe", "full", "aod_full")
class Pipeline:
def __init__(
self,
mode: str = "full",
gamma: float = 1.0,
lowlight: bool = False,
clahe: ClaheEnhancer | None = None,
dehazer: DarkChannelDehazer | None = None,
aod=None,
):
self.set_mode(mode)
self.gamma = gamma
self.lowlight = lowlight
self.clahe = clahe or ClaheEnhancer()
self.dehazer = dehazer or DarkChannelDehazer()
# AOD-Net ๋ํค์ด์ (`aodnet.GatedDehazer` ๋ฑ). `process(bgr)->bgr` ์ธํฐํ์ด์ค๋ง
# ๋ง์ผ๋ฉด ๋ฉ๋๋ค. ์์ผ๋ฉด aod* ๋ชจ๋๋ฅผ ์ธ ๋ ์์ธ โ **DCP๋ก ์กฐ์ฉํ ๋์ฒดํ์ง
# ์์ต๋๋ค.** ๋์ฒดํ๋ฉด "aod ๋ชจ๋๋ก ์ธก์ ํ ๊ฒฐ๊ณผ"๊ฐ ์ค์ ๋ก๋ DCP ๊ฒฐ๊ณผ๊ฐ ๋์ด
# A/B ์คํ์ด ํต์งธ๋ก ๋ฌด์๋ฏธํด์ง๋๋ค.
self.aod = aod
# ๋ง์ง๋ง ํ๋ ์์ ๋จ๊ณ๋ณ ์์์๊ฐ(ms). ๋ณ๋ชฉ ์ถ์ ์ฉ.
self.timings: dict[str, float] = {"dehaze": 0.0, "clahe": 0.0, "total": 0.0}
def set_mode(self, mode: str) -> None:
if mode not in MODES:
raise ValueError(f"mode๋ {MODES} ์ค ํ๋์ฌ์ผ ํฉ๋๋ค (๋ฐ์ ๊ฐ: {mode!r})")
self.mode = mode
def active_dehazer(self):
"""ํ์ฌ mode๊ฐ ์ฐ๋ ๋ํค์ด์ . aod* ๋ชจ๋์ธ๋ฐ ์์ผ๋ฉด ์์ธ."""
if self.mode in AOD_MODES:
if self.aod is None:
raise ValueError(
f"mode={self.mode!r} ์ธ๋ฐ AOD-Net ๋ํค์ด์ ๊ฐ ์์ต๋๋ค. "
"onnx ๊ฒฝ๋ก๋ฅผ ์ฃผ๊ฑฐ๋ dehaze/full ๋ชจ๋๋ฅผ ์ฐ์ธ์. "
"(DCP๋ก ์๋ ๋์ฒดํ์ง ์์ต๋๋ค โ A/B ์คํ์ด ์ค์ผ๋ฉ๋๋ค)"
)
return self.aod
return self.dehazer
def process(self, bgr):
"""bgr uint8 -> bgr uint8. ์
๋ ฅ ๋ฐฐ์ด์ ๋ณ๊ฒฝํ์ง ์์ต๋๋ค."""
t_start = time.perf_counter()
self.timings = {"dehaze": 0.0, "clahe": 0.0, "total": 0.0}
if self.mode == "passthrough":
self.timings["total"] = (time.perf_counter() - t_start) * 1000.0
return bgr
img = apply_gamma(bgr, self.gamma)
if self.mode in DEHAZE_MODES:
dehazer = self.active_dehazer()
t = time.perf_counter()
img = dehazer.process(img)
if self.lowlight:
if not hasattr(dehazer, "process_lowlight"):
# HANDOVER 4-9: AOD-Net์๋ ์ ์กฐ๋ ๋์ ๊ฒฝ๋ก๊ฐ ์์ต๋๋ค.
# ์กฐ์ฉํ ๊ฑด๋๋ฐ๋ฉด "์ ์กฐ๋ ๋ณด์ ์ด ์ผ์ง ์ค ์์๋๋ฐ ์ ๋"
# ์ํ๊ฐ ๋๋ฏ๋ก ๋ง์ต๋๋ค.
raise ValueError(
f"mode={self.mode!r} ์ ๋ํค์ด์ ์๋ process_lowlight๊ฐ "
"์์ต๋๋ค. AOD-Net์ ์ ์กฐ๋ ๋์๋ฌผ์ด ์์ต๋๋ค "
"(HANDOVER 4-9). lowlight๋ฅผ ๋๊ฑฐ๋ dehaze/full์ ์ฐ์ธ์."
)
img = dehazer.process_lowlight(img)
self.timings["dehaze"] = (time.perf_counter() - t) * 1000.0
if self.mode in CLAHE_MODES:
t = time.perf_counter()
img = self.clahe.process(img)
self.timings["clahe"] = (time.perf_counter() - t) * 1000.0
self.timings["total"] = (time.perf_counter() - t_start) * 1000.0
return img
|