Spaces:
Sleeping
Sleeping
from ultralytics import YOLO | |
import cv2 | |
from torch.serialization import add_safe_globals | |
from ultralytics.nn.tasks import DetectionModel | |
class LBWDetector: | |
def __init__(self, model_path='best.pt'): | |
add_safe_globals([DetectionModel]) | |
self.model = YOLO(model_path) | |
def detect_objects(self, frame): | |
results = self.model.predict(source=frame, conf=0.3, save=False, verbose=False) | |
detections = results[0].boxes.data.cpu().numpy() # x1, y1, x2, y2, conf, class | |
return detections, results[0].names | |