shin0624 commited on
Commit
ef5c53e
ยท
verified ยท
1 Parent(s): 1a436d6

Update detector/yolo_pipeline.py

Browse files

๋ชจ๋ธ ๋กœ๋”ฉ ๋ฐฉ์‹ ๊ฐœ์„ 
- ์ „์—ญ ํ•จ์ˆ˜ get_yolo_model()์„ ํ†ตํ•ด ๋ชจ๋ธ ์‹ฑ๊ธ€ํ†ค ๊ด€๋ฆฌ
- ํด๋ž˜์Šค ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ์‹œ ๋ชจ๋ธ ์ฐธ์กฐ ๋Œ€์‹  ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‚ฌ์šฉ

์ง๋ ฌํ™” ๋ฌธ์ œ ํ•ด๊ฒฐ
- YOLO3DReconstructor ํด๋ž˜์Šค๊ฐ€ ์ง์ ‘ ๋ชจ๋ธ ์ธ์Šคํ„ด์Šค๋ฅผ ๋ณด์œ ํ•˜์ง€ ์•Š์Œ
- ์ „์—ญ ๋ชจ๋ธ ์บ์‹ฑ์œผ๋กœ ์ธํ•œ ํ”ผํด๋ง ๋ฌธ์ œ ๋ฐฉ์ง€

๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ ์ตœ์ ํ™”
- ์—ฌ๋Ÿฌ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ์‹œ์—๋„ ๋ชจ๋ธ์€ ํ•œ ๋ฒˆ๋งŒ ๋กœ๋“œ
- GPU ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰ ๊ฐ์†Œ

Files changed (1) hide show
  1. detector/yolo_pipeline.py +26 -21
detector/yolo_pipeline.py CHANGED
@@ -1,48 +1,53 @@
1
- from ultralytics import YOLO
2
- from utils.pointcloud_tools import PointCloudProcessor # ์ถ”๊ฐ€
3
  from spaces import GPU
 
4
  import cv2
5
  import numpy as np
6
  import trimesh
 
 
7
 
8
  @GPU()
9
- # HuggingFace ํ˜ธํ™˜์„ฑ์„ ์œ„ํ•ด ํด๋ž˜์Šค๋ฅผ ์ตœ์ƒ์œ„ ๋ ˆ๋ฒจ๋กœ ์ •์˜
 
 
 
 
 
 
 
 
10
  class YOLO3DReconstructor:
11
- _model_instance = None # ํด๋ž˜์Šค ๋ ˆ๋ฒจ์—์„œ ๋ชจ๋ธ ์บ์‹ฑ
12
-
13
  def __init__(self):
14
- if YOLO3DReconstructor._model_instance is None:
15
- YOLO3DReconstructor._model_instance = YOLO('yolov8m.pt')
16
- self.model = YOLO3DReconstructor._model_instance
17
- self.class_mapping = {
18
- 0: 'person',
19
  7: 'forklift',
20
  63: 'conveyor'
21
  }
22
-
23
  def process_frames(self, frame_paths):
24
  point_cloud = []
25
- detections = {v:0 for v in self.class_mapping.values()}
26
-
27
- for frame_idx, frame_path in enumerate(frame_paths):
28
- img = cv2.imread(frame_path)
29
  if img is None:
30
  continue
31
-
32
  results = self.model(img)[0]
33
  for box in results.boxes.xywh.cpu().numpy():
34
  cls_id = int(box[5])
35
- if cls_id in self.class_mapping:
36
- label = self.class_mapping[cls_id]
37
  detections[label] += 1
38
  x, y, w, h = box[:4]
39
  point_cloud.append([x, y, frame_idx * 50])
40
-
41
  if not point_cloud:
42
  return None
43
-
44
  points = np.array(point_cloud)
45
  points = PointCloudProcessor.filter_outliers(points)
46
  points = PointCloudProcessor.normalize_points(points)
47
 
48
- return trimesh.points.PointCloud(points), detections
 
 
 
1
  from spaces import GPU
2
+ import os
3
  import cv2
4
  import numpy as np
5
  import trimesh
6
+ from ultralytics import YOLO
7
+ from utils.pointcloud_tools import PointCloudProcessor
8
 
9
  @GPU()
10
+ # YOLO ๋ชจ๋ธ ์‹ฑ๊ธ€ํ†ค ์ธ์Šคํ„ด์Šค
11
+ _MODEL = None
12
+
13
+ def get_yolo_model():
14
+ global _MODEL
15
+ if _MODEL is None:
16
+ _MODEL = YOLO('yolov8m.pt')
17
+ return _MODEL
18
+
19
  class YOLO3DReconstructor:
 
 
20
  def __init__(self):
21
+ self.model = get_yolo_model()
22
+ self.class_map = {
23
+ 0: 'person',
 
 
24
  7: 'forklift',
25
  63: 'conveyor'
26
  }
27
+
28
  def process_frames(self, frame_paths):
29
  point_cloud = []
30
+ detections = {v:0 for v in self.class_map.values()}
31
+
32
+ for frame_idx, path in enumerate(frame_paths):
33
+ img = cv2.imread(path)
34
  if img is None:
35
  continue
36
+
37
  results = self.model(img)[0]
38
  for box in results.boxes.xywh.cpu().numpy():
39
  cls_id = int(box[5])
40
+ if cls_id in self.class_map:
41
+ label = self.class_map[cls_id]
42
  detections[label] += 1
43
  x, y, w, h = box[:4]
44
  point_cloud.append([x, y, frame_idx * 50])
45
+
46
  if not point_cloud:
47
  return None
48
+
49
  points = np.array(point_cloud)
50
  points = PointCloudProcessor.filter_outliers(points)
51
  points = PointCloudProcessor.normalize_points(points)
52
 
53
+ return (trimesh.points.PointCloud(points), detections)