Skip to content

Commit 473dd08

Browse files
committed
Handle confidence=None in old inference path
1 parent 42b0a00 commit 473dd08

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

inference/core/models/classification_base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from io import BytesIO
22
from time import perf_counter
3-
from typing import Any, List, Tuple, Union
3+
from typing import Any, List, Optional, Tuple, Union
44

55
import numpy as np
66

@@ -299,7 +299,7 @@ def make_response(
299299
self,
300300
predictions,
301301
img_dims,
302-
confidence: float = 0.5,
302+
confidence: Optional[float] = 0.5,
303303
**kwargs,
304304
) -> Union[ClassificationInferenceResponse, List[ClassificationInferenceResponse]]:
305305
"""
@@ -320,6 +320,11 @@ def make_response(
320320
- Predictions below the confidence threshold are filtered out.
321321
"""
322322
responses = []
323+
# request.dict() unpacking can pass confidence=None explicitly via
324+
# kwargs, which overrides the signature default — coalesce so the
325+
# existing default behavior is preserved.
326+
if confidence is None:
327+
confidence = 0.5
323328
confidence_threshold = float(confidence)
324329
for ind, prediction in enumerate(predictions):
325330
if self.multiclass:

inference/core/models/instance_segmentation_base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, Tuple, Union
1+
from typing import Any, List, Optional, Tuple, Union
22

33
import numpy as np
44

@@ -49,7 +49,7 @@ def infer(
4949
self,
5050
image: Any,
5151
class_agnostic_nms: bool = False,
52-
confidence: float = DEFAULT_CONFIDENCE,
52+
confidence: Optional[float] = DEFAULT_CONFIDENCE,
5353
disable_preproc_auto_orient: bool = False,
5454
disable_preproc_contrast: bool = False,
5555
disable_preproc_grayscale: bool = False,
@@ -94,6 +94,11 @@ def infer(
9494
- Applies non-maximum suppression to the predictions.
9595
- Decodes the masks according to the specified mode.
9696
"""
97+
# request.dict() unpacking can pass confidence=None explicitly, which
98+
# overrides the signature default — coalesce so the existing default
99+
# behavior is preserved.
100+
if confidence is None:
101+
confidence = DEFAULT_CONFIDENCE
97102
return super().infer(
98103
image,
99104
class_agnostic_nms=class_agnostic_nms,

inference/core/models/object_detection_base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def infer(
4343
self,
4444
image: Any,
4545
class_agnostic_nms: bool = DEFAULT_CLASS_AGNOSTIC_NMS,
46-
confidence: float = DEFAULT_CONFIDENCE,
46+
confidence: Optional[float] = DEFAULT_CONFIDENCE,
4747
disable_preproc_auto_orient: bool = False,
4848
disable_preproc_contrast: bool = False,
4949
disable_preproc_grayscale: bool = False,
@@ -81,6 +81,11 @@ def infer(
8181
Raises:
8282
ValueError: If batching is not enabled for the model and more than one image is passed for processing.
8383
"""
84+
# request.dict() unpacking can pass confidence=None explicitly, which
85+
# overrides the signature default — coalesce so the existing default
86+
# behavior is preserved.
87+
if confidence is None:
88+
confidence = DEFAULT_CONFIDENCE
8489
return super().infer(
8590
image,
8691
class_agnostic_nms=class_agnostic_nms,

0 commit comments

Comments
 (0)