Spaces:
Sleeping
Sleeping
update: added new yolo model for UAV detections
Browse files- demo.html +1 -0
- models/detectors/yolov12_bot_sort.py +56 -0
- models/model_loader.py +2 -0
demo.html
CHANGED
|
@@ -254,6 +254,7 @@ button:disabled {
|
|
| 254 |
<option value="owlv2" selected>OWL-V2</option>
|
| 255 |
<option value="hf_yolov8">YOLOv8</option>
|
| 256 |
<option value="hf_yolov8_defence">YOLOv8m Defence</option>
|
|
|
|
| 257 |
</select>
|
| 258 |
|
| 259 |
<button type="button" id="executeButton" onclick="executeMission()" disabled>EXECUTE MISSION</button>
|
|
|
|
| 254 |
<option value="owlv2" selected>OWL-V2</option>
|
| 255 |
<option value="hf_yolov8">YOLOv8</option>
|
| 256 |
<option value="hf_yolov8_defence">YOLOv8m Defence</option>
|
| 257 |
+
<option value="hf_yolov12_bot_sort">YOLOv12 BoT-SORT + ReID</option>
|
| 258 |
</select>
|
| 259 |
|
| 260 |
<button type="button" id="executeButton" onclick="executeMission()" disabled>EXECUTE MISSION</button>
|
models/detectors/yolov12_bot_sort.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from typing import Sequence
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
import torch
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
+
from ultralytics import YOLO
|
| 8 |
+
|
| 9 |
+
from models.detectors.base import DetectionResult, ObjectDetector
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class HuggingFaceYoloV12BotSortDetector(ObjectDetector):
|
| 13 |
+
"""YOLOv12 model (BoT-SORT + ReID) hosted on Hugging Face."""
|
| 14 |
+
|
| 15 |
+
REPO_ID = "wish44165/YOLOv12-BoT-SORT-ReID"
|
| 16 |
+
WEIGHT_FILE = "MOT_yolov12n.pt"
|
| 17 |
+
|
| 18 |
+
def __init__(self, score_threshold: float = 0.3) -> None:
|
| 19 |
+
self.name = "hf_yolov12_bot_sort"
|
| 20 |
+
self.score_threshold = score_threshold
|
| 21 |
+
self.device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 22 |
+
logging.info(
|
| 23 |
+
"Loading Hugging Face YOLOv12 BoT-SORT weights %s/%s onto %s",
|
| 24 |
+
self.REPO_ID,
|
| 25 |
+
self.WEIGHT_FILE,
|
| 26 |
+
self.device,
|
| 27 |
+
)
|
| 28 |
+
weight_path = hf_hub_download(repo_id=self.REPO_ID, filename=self.WEIGHT_FILE)
|
| 29 |
+
self.model = YOLO(weight_path)
|
| 30 |
+
self.model.to(self.device)
|
| 31 |
+
self.class_names = self.model.names
|
| 32 |
+
|
| 33 |
+
def predict(self, frame: np.ndarray, queries: Sequence[str]) -> DetectionResult:
|
| 34 |
+
device_arg = 0 if self.device.startswith("cuda") else "cpu"
|
| 35 |
+
results = self.model.predict(
|
| 36 |
+
source=frame,
|
| 37 |
+
device=device_arg,
|
| 38 |
+
conf=self.score_threshold,
|
| 39 |
+
verbose=False,
|
| 40 |
+
)
|
| 41 |
+
result = results[0]
|
| 42 |
+
boxes = result.boxes
|
| 43 |
+
if boxes is None or boxes.xyxy is None:
|
| 44 |
+
empty = np.empty((0, 4), dtype=np.float32)
|
| 45 |
+
return DetectionResult(empty, [], [], [])
|
| 46 |
+
|
| 47 |
+
xyxy = boxes.xyxy.cpu().numpy()
|
| 48 |
+
scores = boxes.conf.cpu().numpy().tolist()
|
| 49 |
+
label_ids = boxes.cls.cpu().numpy().astype(int).tolist()
|
| 50 |
+
label_names = [self.class_names.get(idx, f"class_{idx}") for idx in label_ids]
|
| 51 |
+
return DetectionResult(
|
| 52 |
+
boxes=xyxy,
|
| 53 |
+
scores=scores,
|
| 54 |
+
labels=label_ids,
|
| 55 |
+
label_names=label_names,
|
| 56 |
+
)
|
models/model_loader.py
CHANGED
|
@@ -6,6 +6,7 @@ from models.detectors.base import ObjectDetector
|
|
| 6 |
from models.detectors.owlv2 import Owlv2Detector
|
| 7 |
from models.detectors.yolov8 import HuggingFaceYoloV8Detector
|
| 8 |
from models.detectors.yolov8_defence import HuggingFaceYoloV8DefenceDetector
|
|
|
|
| 9 |
|
| 10 |
DEFAULT_DETECTOR = "owlv2"
|
| 11 |
|
|
@@ -13,6 +14,7 @@ _REGISTRY: Dict[str, Callable[[], ObjectDetector]] = {
|
|
| 13 |
"owlv2": Owlv2Detector,
|
| 14 |
"hf_yolov8": HuggingFaceYoloV8Detector,
|
| 15 |
"hf_yolov8_defence": HuggingFaceYoloV8DefenceDetector,
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
|
|
|
|
| 6 |
from models.detectors.owlv2 import Owlv2Detector
|
| 7 |
from models.detectors.yolov8 import HuggingFaceYoloV8Detector
|
| 8 |
from models.detectors.yolov8_defence import HuggingFaceYoloV8DefenceDetector
|
| 9 |
+
from models.detectors.yolov12_bot_sort import HuggingFaceYoloV12BotSortDetector
|
| 10 |
|
| 11 |
DEFAULT_DETECTOR = "owlv2"
|
| 12 |
|
|
|
|
| 14 |
"owlv2": Owlv2Detector,
|
| 15 |
"hf_yolov8": HuggingFaceYoloV8Detector,
|
| 16 |
"hf_yolov8_defence": HuggingFaceYoloV8DefenceDetector,
|
| 17 |
+
"hf_yolov12_bot_sort": HuggingFaceYoloV12BotSortDetector,
|
| 18 |
}
|
| 19 |
|
| 20 |
|