Update detect_bubbles.py
Browse files- detect_bubbles.py +6 -15
detect_bubbles.py
CHANGED
|
@@ -1,28 +1,19 @@
|
|
| 1 |
from ultralytics import YOLO
|
| 2 |
-
import torch
|
| 3 |
|
| 4 |
-
torch.serialization.add_safe_globals([YOLO, 'DetectionModel'])
|
| 5 |
-
|
| 6 |
-
def safe_load_model(model_path):
|
| 7 |
-
"""
|
| 8 |
-
Manually loads the YOLO model weights with 'weights_only' set to False
|
| 9 |
-
to avoid the security check issue with PyTorch.
|
| 10 |
-
"""
|
| 11 |
-
model = YOLO(model_path, weights_only=False)
|
| 12 |
-
return model
|
| 13 |
|
| 14 |
def detect_bubbles(model_path, image_path):
|
| 15 |
"""
|
| 16 |
Detects bubbles in an image using a YOLOv8 model.
|
|
|
|
| 17 |
Args:
|
| 18 |
model_path (str): The file path to the YOLO model.
|
| 19 |
image_path (str): The file path to the input image.
|
|
|
|
| 20 |
Returns:
|
| 21 |
-
list: A list containing the coordinates, score
|
| 22 |
the detected bubbles.
|
| 23 |
"""
|
| 24 |
-
model =
|
| 25 |
-
|
| 26 |
-
bubbles = results[0].boxes.data.tolist()
|
| 27 |
|
| 28 |
-
return bubbles
|
|
|
|
| 1 |
from ultralytics import YOLO
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def detect_bubbles(model_path, image_path):
|
| 5 |
"""
|
| 6 |
Detects bubbles in an image using a YOLOv8 model.
|
| 7 |
+
|
| 8 |
Args:
|
| 9 |
model_path (str): The file path to the YOLO model.
|
| 10 |
image_path (str): The file path to the input image.
|
| 11 |
+
|
| 12 |
Returns:
|
| 13 |
+
list: A list containing the coordinates, score and class_id of
|
| 14 |
the detected bubbles.
|
| 15 |
"""
|
| 16 |
+
model = YOLO(model_path)
|
| 17 |
+
bubbles = model(image_path)[0]
|
|
|
|
| 18 |
|
| 19 |
+
return bubbles.boxes.data.tolist()
|