Spaces:
Sleeping
Sleeping
Update detector/yolo_pipeline.py
Browse files
detector/yolo_pipeline.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
from spaces import GPU
|
| 2 |
import os
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
|
@@ -6,8 +5,7 @@ import trimesh
|
|
| 6 |
from ultralytics import YOLO
|
| 7 |
from utils.pointcloud_tools import PointCloudProcessor
|
| 8 |
|
| 9 |
-
|
| 10 |
-
# ์ ์ญ ๋ชจ๋ธ ์ธ์คํด์ค ์ด๊ธฐํ
|
| 11 |
_MODEL = None
|
| 12 |
|
| 13 |
def get_yolo_model():
|
|
@@ -21,11 +19,13 @@ class YOLO3DReconstructor:
|
|
| 21 |
self.model = get_yolo_model()
|
| 22 |
self.class_mapping = {
|
| 23 |
0: 'person',
|
| 24 |
-
7: '
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
-
|
| 28 |
-
@GPU
|
| 29 |
def process_frames(self, frame_paths):
|
| 30 |
point_cloud = []
|
| 31 |
detections = {v: 0 for v in self.class_mapping.values()}
|
|
@@ -38,7 +38,7 @@ class YOLO3DReconstructor:
|
|
| 38 |
results = self.model(img)[0]
|
| 39 |
|
| 40 |
# ๊ฐ์ง ๊ฒฐ๊ณผ๊ฐ ์๋ ๊ฒฝ์ฐ ๊ฑด๋๋ฐ๊ธฐ
|
| 41 |
-
if
|
| 42 |
continue
|
| 43 |
|
| 44 |
boxes_xywh = results.boxes.xywh.cpu().numpy()
|
|
@@ -60,4 +60,4 @@ class YOLO3DReconstructor:
|
|
| 60 |
points = PointCloudProcessor.filter_outliers(points)
|
| 61 |
points = PointCloudProcessor.normalize_points(points)
|
| 62 |
|
| 63 |
-
return (trimesh.points.PointCloud(points), detections)
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
|
|
|
| 5 |
from ultralytics import YOLO
|
| 6 |
from utils.pointcloud_tools import PointCloudProcessor
|
| 7 |
|
| 8 |
+
# YOLO ๋ชจ๋ธ ์ธ์คํด์ค ์ด๊ธฐํ
|
|
|
|
| 9 |
_MODEL = None
|
| 10 |
|
| 11 |
def get_yolo_model():
|
|
|
|
| 19 |
self.model = get_yolo_model()
|
| 20 |
self.class_mapping = {
|
| 21 |
0: 'person',
|
| 22 |
+
7: 'truck', # ํธ๋ญ์ด ํฌํฌ๋ฆฌํํธ์ ๊ฐ์ฅ ๊ฐ๊น์ด COCO ํด๋์ค
|
| 23 |
+
24: 'backpack', # ๊ธฐํ ๊ณต์ฅ ์ฅ๋น๋ก ํ์ฉ ๊ฐ๋ฅํ ๋์ฒด ํด๋์ค
|
| 24 |
+
41: 'cup', # ๊ธฐํ ๊ณต์ฅ ์ฅ๋น๋ก ํ์ฉ ๊ฐ๋ฅํ ๋์ฒด ํด๋์ค
|
| 25 |
+
73: 'laptop' # ๊ธฐํ ๊ณต์ฅ ์ฅ๋น๋ก ํ์ฉ ๊ฐ๋ฅํ ๋์ฒด ํด๋์ค
|
| 26 |
}
|
| 27 |
+
# ์๋ณธ ์ฝ๋์ 'forklift'์ 'conveyor' ํด๋์ค๊ฐ COCO ๋ฐ์ดํฐ์
์ ์์ด์ ์ ์ฌํ ํด๋์ค๋ก ๋์ฒด
|
| 28 |
+
@GPU
|
| 29 |
def process_frames(self, frame_paths):
|
| 30 |
point_cloud = []
|
| 31 |
detections = {v: 0 for v in self.class_mapping.values()}
|
|
|
|
| 38 |
results = self.model(img)[0]
|
| 39 |
|
| 40 |
# ๊ฐ์ง ๊ฒฐ๊ณผ๊ฐ ์๋ ๊ฒฝ์ฐ ๊ฑด๋๋ฐ๊ธฐ
|
| 41 |
+
if len(results.boxes) == 0:
|
| 42 |
continue
|
| 43 |
|
| 44 |
boxes_xywh = results.boxes.xywh.cpu().numpy()
|
|
|
|
| 60 |
points = PointCloudProcessor.filter_outliers(points)
|
| 61 |
points = PointCloudProcessor.normalize_points(points)
|
| 62 |
|
| 63 |
+
return (trimesh.points.PointCloud(points), detections)
|