Spaces:
Paused
Paused
Zhen Ye
commited on
Commit
·
2392266
1
Parent(s):
e43c504
Simplify drone YOLO loading with ultralytics native HF Hub support
Browse files
models/detectors/drone_yolo.py
CHANGED
|
@@ -4,7 +4,6 @@ from typing import List, Sequence
|
|
| 4 |
|
| 5 |
import numpy as np
|
| 6 |
import torch
|
| 7 |
-
from huggingface_hub import hf_hub_download
|
| 8 |
from ultralytics import YOLO
|
| 9 |
|
| 10 |
from models.detectors.base import DetectionResult, ObjectDetector
|
|
@@ -14,7 +13,6 @@ class DroneYoloDetector(ObjectDetector):
|
|
| 14 |
"""Drone detector backed by a YOLO model on the Hugging Face Hub."""
|
| 15 |
|
| 16 |
REPO_ID = "rujutashashikanjoshi/yolo12-drone-detection-0205-100m"
|
| 17 |
-
DEFAULT_WEIGHT = "best.pt"
|
| 18 |
supports_batch = True
|
| 19 |
max_batch_size = 8
|
| 20 |
|
|
@@ -25,15 +23,13 @@ class DroneYoloDetector(ObjectDetector):
|
|
| 25 |
self.device = device
|
| 26 |
else:
|
| 27 |
self.device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 28 |
-
weight_file = os.getenv("DRONE_YOLO_WEIGHT", self.DEFAULT_WEIGHT)
|
| 29 |
logging.info(
|
| 30 |
-
"Loading drone YOLO
|
| 31 |
self.REPO_ID,
|
| 32 |
-
weight_file,
|
| 33 |
self.device,
|
| 34 |
)
|
| 35 |
-
|
| 36 |
-
self.model = YOLO(
|
| 37 |
self.model.to(self.device)
|
| 38 |
self.class_names = self.model.names
|
| 39 |
|
|
|
|
| 4 |
|
| 5 |
import numpy as np
|
| 6 |
import torch
|
|
|
|
| 7 |
from ultralytics import YOLO
|
| 8 |
|
| 9 |
from models.detectors.base import DetectionResult, ObjectDetector
|
|
|
|
| 13 |
"""Drone detector backed by a YOLO model on the Hugging Face Hub."""
|
| 14 |
|
| 15 |
REPO_ID = "rujutashashikanjoshi/yolo12-drone-detection-0205-100m"
|
|
|
|
| 16 |
supports_batch = True
|
| 17 |
max_batch_size = 8
|
| 18 |
|
|
|
|
| 23 |
self.device = device
|
| 24 |
else:
|
| 25 |
self.device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 26 |
logging.info(
|
| 27 |
+
"Loading drone YOLO from HuggingFace Hub: %s onto %s",
|
| 28 |
self.REPO_ID,
|
|
|
|
| 29 |
self.device,
|
| 30 |
)
|
| 31 |
+
# Load directly from HuggingFace Hub using ultralytics native support
|
| 32 |
+
self.model = YOLO(f"hf://{self.REPO_ID}")
|
| 33 |
self.model.to(self.device)
|
| 34 |
self.class_names = self.model.names
|
| 35 |
|