Spaces:
Sleeping
Sleeping
yolo추론 스크립트
Browse files
detect.py
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
from ultralytics import YOLO
|
| 2 |
import cv2
|
| 3 |
|
| 4 |
-
#
|
| 5 |
TARGET_CLASSES = {
|
| 6 |
0: 'person',
|
| 7 |
-
2: '
|
| 8 |
-
39: '
|
| 9 |
-
67: '
|
| 10 |
}
|
| 11 |
|
| 12 |
def run_detection(image, model):
|
| 13 |
results = model(image)[0]
|
| 14 |
detections = []
|
| 15 |
-
|
| 16 |
for box in results.boxes:
|
| 17 |
cls_id = int(box.cls.item())
|
| 18 |
if cls_id in TARGET_CLASSES:
|
|
@@ -20,4 +20,4 @@ def run_detection(image, model):
|
|
| 20 |
x, y = box.xywh[0][:2].tolist()
|
| 21 |
detections.append((name, (x, y)))
|
| 22 |
|
| 23 |
-
return detections
|
|
|
|
| 1 |
from ultralytics import YOLO
|
| 2 |
import cv2
|
| 3 |
|
| 4 |
+
# 클래스 매핑 (YOLOv8 COCO 기준)
|
| 5 |
TARGET_CLASSES = {
|
| 6 |
0: 'person',
|
| 7 |
+
2: 'forklift', # car로 대체 (fine-tune 필요)
|
| 8 |
+
39: 'machine', # screwdriver → 기계 대체
|
| 9 |
+
67: 'conveyor_belt' # cell phone → 벨트 대체
|
| 10 |
}
|
| 11 |
|
| 12 |
def run_detection(image, model):
|
| 13 |
results = model(image)[0]
|
| 14 |
detections = []
|
| 15 |
+
|
| 16 |
for box in results.boxes:
|
| 17 |
cls_id = int(box.cls.item())
|
| 18 |
if cls_id in TARGET_CLASSES:
|
|
|
|
| 20 |
x, y = box.xywh[0][:2].tolist()
|
| 21 |
detections.append((name, (x, y)))
|
| 22 |
|
| 23 |
+
return detections
|