georgescutelnicu commited on
Commit
ae4fcd6
·
verified ·
1 Parent(s): 6a0ffea

Update detect_bubbles.py

Browse files
Files changed (1) hide show
  1. detect_bubbles.py +6 -8
detect_bubbles.py CHANGED
@@ -1,21 +1,19 @@
1
- from ultralytics import YOLO
2
  import torch.serialization
3
-
4
- torch.serialization.add_safe_globals([YOLO])
5
 
6
  def detect_bubbles(model_path, image_path):
7
  """
8
  Detects bubbles in an image using a YOLOv8 model.
9
-
10
  Args:
11
  model_path (str): The file path to the YOLO model.
12
  image_path (str): The file path to the input image.
13
-
14
  Returns:
15
- list: A list containing the coordinates, score and class_id of
16
  the detected bubbles.
17
  """
18
- model = YOLO(model_path)
 
 
19
  bubbles = model(image_path)[0]
20
 
21
- return bubbles.boxes.data.tolist()
 
 
1
  import torch.serialization
2
+ from ultralytics import YOLO
 
3
 
4
  def detect_bubbles(model_path, image_path):
5
  """
6
  Detects bubbles in an image using a YOLOv8 model.
 
7
  Args:
8
  model_path (str): The file path to the YOLO model.
9
  image_path (str): The file path to the input image.
 
10
  Returns:
11
+ list: A list containing the coordinates, score, and class_id of
12
  the detected bubbles.
13
  """
14
+ with torch.serialization.safe_globals([YOLO]):
15
+ model = YOLO(model_path)
16
+
17
  bubbles = model(image_path)[0]
18
 
19
+ return bubbles.boxes.data.tolist()