Safemotion Lib
Loading...
Searching...
No Matches
yolov8_runner.py
Go to the documentation of this file.
1from ultralytics import YOLO
2
3class YoloV8Runner(object):
4 """
5 YOLO 모델을 동작시키기 위한 클래스
6 args:
7 checkpoint (str): 모델 파라미터 저장 경로, engine 파일(TensorRT 모델) 또는 pt 파일(torch 모델)
8 kwargs (str): 모델 동작을 위한 기타 파라미터
9 """
10 def __init__(self, checkpoint, **kwargs):
11 self.model = YOLO(checkpoint)
12 self.kwargs = kwargs
13
14 def run_detector(self, image):
15 """
16 객체 검출기를 동작시키는 기능
17 args:
18 image (np.ndarray): RGB? BGR? 이미지
19 """
20
21 results = self.model.predict(source=image, **self.kwargs)
22
23 data = {}
24 data['det_bboxes'] = results[0].boxes.data.cpu()[:, :5]
25 data['det_labels'] = results[0].boxes.cls.cpu()
26
27 return data
28
__init__(self, checkpoint, **kwargs)