shin0624 commited on
Commit
a983cb6
ยท
verified ยท
1 Parent(s): 4086071

Update detector/yolo_pipeline.py

Browse files
Files changed (1) hide show
  1. detector/yolo_pipeline.py +17 -6
detector/yolo_pipeline.py CHANGED
@@ -6,6 +6,7 @@ import trimesh
6
  from ultralytics import YOLO
7
  from utils.pointcloud_tools import PointCloudProcessor
8
 
 
9
  # ์ „์—ญ ๋ชจ๋ธ ์ธ์Šคํ„ด์Šค ์ดˆ๊ธฐํ™”
10
  _MODEL = None
11
 
@@ -23,10 +24,11 @@ class YOLO3DReconstructor:
23
  7: 'forklift',
24
  63: 'conveyor'
25
  }
 
26
  @GPU()
27
  def process_frames(self, frame_paths):
28
  point_cloud = []
29
- detections = {v:0 for v in self.class_mapping.values()}
30
 
31
  for frame_idx, path in enumerate(frame_paths):
32
  img = cv2.imread(path)
@@ -34,19 +36,28 @@ class YOLO3DReconstructor:
34
  continue
35
 
36
  results = self.model(img)[0]
37
- for box in results.boxes.xywh.cpu().numpy():
38
- cls_id = int(box[5])
 
 
 
 
 
 
 
 
39
  if cls_id in self.class_mapping:
40
  label = self.class_mapping[cls_id]
41
  detections[label] += 1
42
  x, y, w, h = box[:4]
43
- point_cloud.append([x, y, frame_idx * 50])
44
 
45
  if not point_cloud:
46
  return None
47
 
 
48
  points = np.array(point_cloud)
49
  points = PointCloudProcessor.filter_outliers(points)
50
  points = PointCloudProcessor.normalize_points(points)
51
-
52
- return (trimesh.points.PointCloud(points), detections)
 
6
  from ultralytics import YOLO
7
  from utils.pointcloud_tools import PointCloudProcessor
8
 
9
+
10
  # ์ „์—ญ ๋ชจ๋ธ ์ธ์Šคํ„ด์Šค ์ดˆ๊ธฐํ™”
11
  _MODEL = None
12
 
 
24
  7: 'forklift',
25
  63: 'conveyor'
26
  }
27
+ # GPU ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰
28
  @GPU()
29
  def process_frames(self, frame_paths):
30
  point_cloud = []
31
+ detections = {v: 0 for v in self.class_mapping.values()}
32
 
33
  for frame_idx, path in enumerate(frame_paths):
34
  img = cv2.imread(path)
 
36
  continue
37
 
38
  results = self.model(img)[0]
39
+
40
+ # ๊ฐ์ง€ ๊ฒฐ๊ณผ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ ๊ฑด๋„ˆ๋›ฐ๊ธฐ
41
+ if results.boxes.xywh.numel() == 0 or results.boxes.cls.numel() == 0:
42
+ continue
43
+
44
+ boxes_xywh = results.boxes.xywh.cpu().numpy()
45
+ class_ids = results.boxes.cls.cpu().numpy()
46
+
47
+ for box, cls in zip(boxes_xywh, class_ids):
48
+ cls_id = int(cls)
49
  if cls_id in self.class_mapping:
50
  label = self.class_mapping[cls_id]
51
  detections[label] += 1
52
  x, y, w, h = box[:4]
53
+ point_cloud.append([x, y, frame_idx * 50]) # z์ถ•์— ํ”„๋ ˆ์ž„ ์ˆœ์„œ ๋ฐ˜์˜
54
 
55
  if not point_cloud:
56
  return None
57
 
58
+ # ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ ํ›„์ฒ˜๋ฆฌ
59
  points = np.array(point_cloud)
60
  points = PointCloudProcessor.filter_outliers(points)
61
  points = PointCloudProcessor.normalize_points(points)
62
+
63
+ return (trimesh.points.PointCloud(points), detections)