generated from roboflow/template-python
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Search before asking
- I have searched the Supervision issues and found no similar bug report.
Bug
InferenceSlicer throws Segmentation fault with thread_workers = 4:
Segmentation fault (core dumped)
Environment
Supervision 0.24.0
Python 3.11
Minimal Reproducible Example
from ultralytics import YOLO
import cv2
import sys
import torch
import numpy as np
from pathlib import Path
import math
import supervision as sv
def callback(image_slice: np.ndarray) -> sv.Detections:
result = model(image_slice, conf=0.6)
print("Results:", result)
return sv.Detections.from_ultralytics(result[0])
model = YOLO('yolo11x-obb.pt')
print("GPU:", torch.cuda.is_available())
if torch.cuda.is_available():
device = torch.device("cuda")
print("Using GPU:", torch.cuda.get_device_name())
# load image
file_name = Path(sys.argv[1])
image = cv2.imread(sys.argv[1]) #Image.open(file_name, mode='r')
print("Loaded image:", file_name)
image_wh = (image.shape[1], image.shape[0])
slice_wh = (1024, 1024)
overlap_ratio_wh = (0.2, 0.2)
overlap_ratio_w, overlap_ratio_h = overlap_ratio_wh
slice_w, slice_h = slice_wh
overlap_wh = (math.ceil(slice_w * overlap_ratio_w), math.ceil(slice_h * overlap_ratio_h))
slicer = sv.InferenceSlicer(
callback=callback,
overlap_filter=sv.OverlapFilter.NON_MAX_MERGE,
iou_threshold=0.15,
slice_wh=slice_wh,
overlap_ratio_wh=None,
overlap_wh=overlap_wh,
thread_workers=2
)
detections = slicer(image)
labels = [
f"{class_name} {confidence:.1f}"
for class_name, confidence
in zip(detections['class_name'], detections.confidence)
]
label_annotator = sv.LabelAnnotator(text_scale=0.2, text_thickness=1, text_padding=0, text_position=sv.Position.TOP_LEFT)
bbox_annotator = sv.BoxAnnotator(color=sv.ColorPalette.DEFAULT.colors[6], thickness=2)
obb_annotator = sv.OrientedBoxAnnotator(color=sv.ColorPalette.DEFAULT.colors[6], thickness=2)
print(f"Image shape: {image_wh[0]}w x {image_wh[1]}h")
print(f"Tile size: {slice_wh[0]}w x {slice_wh[1]}h")
print(f"Overlap: {overlap_wh[0]}w x {overlap_wh[1]}h. Ratio {overlap_ratio_wh}")
print(f"Overlap Filter: {sv.OverlapFilter.NON_MAX_MERGE}")
print(f"Found {len(detections)} objects")
annotated_image = obb_annotator.annotate(scene=image.copy(), detections=detections)
annotated_image = label_annotator.annotate(scene=annotated_image, detections=detections, labels=labels)
cv2.imwrite(file_name.stem + "-output.jpg", annotated_image)

Additional
To reproduce:
python detect-image-slicer-bug.py airplane-graveyard-zoomed.jpg
Are you willing to submit a PR?
- Yes I'd like to help by submitting a PR!
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working