Skip to content

Repeat detections with InferenceSlicer #1814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 2 tasks
robmarkcole opened this issue Apr 2, 2025 · 1 comment
Open
1 of 2 tasks

Repeat detections with InferenceSlicer #1814

robmarkcole opened this issue Apr 2, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@robmarkcole
Copy link

Search before asking

  • I have searched the Supervision issues and found no similar bug report.

Bug

The detections show a clear repeat pattern:

Image

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

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!
@robmarkcole robmarkcole added the bug Something isn't working label Apr 2, 2025
@SkalskiP
Copy link
Collaborator

Hi @robmarkcole 👋🏻 have you tried to manipulate iou_threshold value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants