How to use Double Detection Filter in Supervision library?

I’m trying to follow the documentation and examples cited at effectively picking the higher confidence predictions for double detections.

and Double Detection Filter - Supervision

Below is an example image in question and my clarifications are regarding the two types of overlaps (encircled in orange and green)

Orange circle: What is the approach to pick the prediction with the higher confidence in this case?

Green circles: What some ways to think about thresholds that let us ignore the smaller enclosed predictions/ boxes?

It feels like I am mixing up the thresholds and the detection strategies.
Would someone mind clarifying the way to think about approaching detections in the above two scenarios?

This is current implementation.

def callback(image_slice: np.ndarray) → sv.Detections:
_, buffer = cv2.imencode(‘.jpg’, image_slice)
image_bytes = buffer.tobytes()

response =
    params={"api_key": ROBOFLOW_API_KEY,
            "confidence": 45,
            "overlap": 10 },
    files={"file": image_bytes}

response_data = response.json()
return sv.Detections.from_inference(response_data).with_nms(threshold=0.1)

image = cv2.imread(image_path)
slicer = sv.InferenceSlicer(
slice_wh=(1000, 752),
detections = slicer(image)

For full context:
4000x3008 image is sliced into 1000x752 tiles for inference

Hi @kedar :wave:

If there are cases of clear overlap such as the green circles, I’d start with those first. Filtering out misdetections & cleaning the data is a good first step.

Since you wish to merge with the larger box, non-max merge and a threshold of about 0.1 - 0.05 is the correct approach. I’d run over multiple examples of your data until I can narrow down on a realistic number.

If this does not work, I’d look into a custom solution. For example, it seems like your model produces boxes that are confined within others. You could create a system that compares each boxes by how much one is NOT encapsulated in another. Then given 2 detections, if you check that A is almost entirely in B, it’s likely to be the green circle case.

For the orange circle, I’m not certain of what you wish to detect. Can you explain a little bit more?


  1. As a clarification, is using with_nms(threshold=(0.1-0.05) here your suggested approach? The reason I’m a bit confused is I’m trying to better understand how this works in conjunction with the overlap threshold specified as %.

  2. The orange circle is an example of two predictions for the same object with different confidence scores. Behind the black bounding box is a purple one occluded.

Many thanks for your guidance @linas :pray:

I’ve updated a blog post a few days ago, on detecting small objects. Let me know if that explains it well enough:

Then, there’s an in-depth article by Piotr, explaining non-max suppression step-by-step:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.