feat: 🚀 allow per-call confidence_threshold override in prediction APIs#1352
Merged
onuralpszr merged 4 commits intomainfrom Apr 19, 2026
Merged
feat: 🚀 allow per-call confidence_threshold override in prediction APIs#1352onuralpszr merged 4 commits intomainfrom
onuralpszr merged 4 commits intomainfrom
Conversation
Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
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
approved these changes
Apr 19, 2026
Collaborator
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AutoDetectionModel.from_pretrained()has always acceptedconfidence_threshold, butget_prediction()andget_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_thresholdfor that call and restores the original value before returning, so the model state is unchanged after the call.Related discussion topic: #1269