Skip to content

feat: 🚀 allow per-call confidence_threshold override in prediction APIs#1352

Merged
onuralpszr merged 4 commits intomainfrom
feat/get_sliced_prediction
Apr 19, 2026
Merged

feat: 🚀 allow per-call confidence_threshold override in prediction APIs#1352
onuralpszr merged 4 commits intomainfrom
feat/get_sliced_prediction

Conversation

@onuralpszr
Copy link
Copy Markdown
Collaborator

@onuralpszr onuralpszr commented Apr 19, 2026

AutoDetectionModel.from_pretrained() has always accepted confidence_threshold, but get_prediction() and get_sliced_prediction() had no way to override it without mutating the model object directly. This made dynamic threshold usage (e.g. sweeping thresholds, per-image tuning) awkward.

Both functions now accept an optional confidence_threshold parameter. When provided, it overrides detection_model.confidence_threshold for that call and restores the original value before returning, so the model state is unchanged after the call.

result = get_sliced_prediction(image, model, confidence_threshold=0.7)
# model.confidence_threshold is unchanged after this call

Related discussion topic: #1269

Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
@onuralpszr onuralpszr requested a review from fcakyon April 19, 2026 20:03
@onuralpszr
Copy link
Copy Markdown
Collaborator Author

PTAL @fcakyon when you had time.

sweep conf approach usage

from sahi import AutoDetectionModel
from sahi.predict import get_prediction
model = AutoDetectionModel.from_pretrained(
        model_type="ultralytics",
        model_path="yolo11n.pt",
        confidence_threshold=0.3,
    )
# run with a different threshold without changing the model
result = get_prediction("image.jpg", model, confidence_threshold=0.7)
print(model.confidence_threshold)  # still 0.3

…ion and get_sliced_prediction

Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
@fcakyon
Copy link
Copy Markdown
Collaborator

fcakyon commented Apr 19, 2026

looks good 👍🏻

…ction functions

Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
…diction and get_sliced_prediction functions

Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
@onuralpszr onuralpszr merged commit 42f975a into main Apr 19, 2026
9 checks passed
@onuralpszr onuralpszr deleted the feat/get_sliced_prediction branch April 19, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants