Skip to content

Commit 46bf44b

Browse files
author
Tim Huff
committed
Fix spurious Unrecognized internal label warnings on non-binary detectors
1 parent ca6838a commit 46bf44b

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/groundlight/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
ROI,
3030
AccountMonthToDateInfo,
3131
BBoxGeometry,
32-
BinaryClassificationResult,
3332
Detector,
3433
DetectorGroup,
3534
ImageQuery,
3635
ModeEnum,
3736
PaginatedDetectorList,
3837
PaginatedImageQueryList,
38+
ResultTypeEnum,
3939
)
4040
from urllib3.exceptions import InsecureRequestWarning
4141
from urllib3.util.retry import Retry
@@ -242,8 +242,13 @@ def _fixup_image_query(iq: ImageQuery) -> ImageQuery:
242242
"""
243243
# Note: This might go away once we clean up the mapping logic server-side.
244244

245-
# we have to check that result is not None because the server will return a result of None if want_async=True
246-
if isinstance(iq.result, BinaryClassificationResult):
245+
# Gate on the discriminator (`iq.result_type`) rather than on `isinstance(iq.result, ...)`.
246+
# `ImageQuery.result` is a non-discriminated Pydantic Union; because `BinaryClassificationResult`
247+
# is listed first and every `*Result` subclass has a near-identical shape, results from non-binary
248+
# detectors (counting, multi-class, bounding box, text) all get parsed as `BinaryClassificationResult`,
249+
# which would otherwise route their labels (e.g. "BOUNDING_BOX") through binary YES/NO conversion.
250+
# `iq.result` may also be None when the server returns no result yet (e.g. want_async=True).
251+
if iq.result is not None and iq.result_type == ResultTypeEnum.binary_classification:
247252
iq.result.label = convert_internal_label_to_display(iq, iq.result.label)
248253
return iq
249254

0 commit comments

Comments
 (0)