Spaces:
Runtime error
Runtime error
Update models/detection/detector.py
Browse files
models/detection/detector.py
CHANGED
|
@@ -28,12 +28,12 @@ class ObjectDetector:
|
|
| 28 |
)
|
| 29 |
|
| 30 |
def load_model(self):
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
|
| 39 |
def predict(self, image: Image.Image, conf_threshold=0.25):
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
def load_model(self):
|
| 31 |
+
if self.model is None:
|
| 32 |
+
from ultralytics import YOLO # Deferring import to avoid early CUDA trigger
|
| 33 |
+
self.model = YOLO(self.weights_path)
|
| 34 |
+
if self.device == "cuda" and torch.cuda.is_available():
|
| 35 |
+
self.model.to("cuda")
|
| 36 |
+
return self
|
| 37 |
|
| 38 |
|
| 39 |
def predict(self, image: Image.Image, conf_threshold=0.25):
|