lbw_drs_app / detector.py
dschandra's picture
Update detector.py
340ad0f verified
raw
history blame contribute delete
758 Bytes
from ultralytics import YOLO
import cv2
import torch
class LBWDetector:
def __init__(self, model_path='best.pt'):
# Temporarily override torch.load to use weights_only=False
original_load = torch.load
def custom_load(*args, **kwargs):
kwargs['weights_only'] = False
return original_load(*args, **kwargs)
torch.load = custom_load
self.model = YOLO(model_path)
# Restore original torch.load
torch.load = original_load
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