generated from roboflow/template-python
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
The detections show a clear repeat pattern:
There are 720 detections, but when I check the confidence
values, there are only 6 unique confidence values - i.e. appears detections are somehow mirrored to other locations on the image
Environment
- sv = 0.25.1
Minimal Reproducible Example
import os
import cv2
import numpy as np
import pandas as pd
from glob import glob
from dotenv import load_dotenv
import supervision as sv
from inference import get_model
# Load environment variables (e.g., from .env file)
load_dotenv()
api_key = os.getenv("ROBOFLOW_API_KEY")
# Load the Roboflow model
model = get_model(model_id="your-model-id", api_key=api_key) # anonymized model ID
# Constants
PATCH_SIZE = 640
image_dir = "your-image-dir" # replace with actual directory path
images = glob(f"{image_dir}/*.png")
# Read an image
image_file = images[1] # change index as needed
image = cv2.imread(image_file)
# Define inference callback
def callback(image_slice: np.ndarray) -> sv.Detections:
result = model.infer(image)[0]
return sv.Detections.from_inference(result)
# Set up slicer
slicer = sv.InferenceSlicer(
callback=callback,
overlap_filter=sv.OverlapFilter.NON_MAX_SUPPRESSION,
slice_wh=(PATCH_SIZE, PATCH_SIZE),
thread_workers=1,
)
# Run inference with slicing
detections = slicer(image)
print(f"Number of detections: {len(detections)}")
# Annotate results
bounding_box_annotator = sv.BoxAnnotator(
color=sv.ColorPalette.DEFAULT.colors[8],
thickness=2
)
label_annotator = sv.LabelAnnotator()
labels = [
f"{confidence:.2f}"
for class_id, confidence in zip(detections.class_id, detections.confidence)
]
annotated_image = bounding_box_annotator.annotate(scene=image, detections=detections)
annotated_image = label_annotator.annotate(
annotated_image, detections=detections, labels=labels
)
# Save results to CSV
csv_sink = sv.CSVSink("out.csv")
with csv_sink as sink:
sink.append(detections, {})
# Load CSV into DataFrame for inspection
df = pd.read_csv("out.csv")
print(f"Detections saved: {len(df)}")
print(df.sort_values(by="confidence", ascending=False).head())
Additional
No response
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