Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/groundlight/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
ROI,
AccountMonthToDateInfo,
BBoxGeometry,
BinaryClassificationResult,
Detector,
DetectorGroup,
ImageQuery,
ModeEnum,
PaginatedDetectorList,
PaginatedImageQueryList,
ResultTypeEnum,
)
from urllib3.exceptions import InsecureRequestWarning
from urllib3.util.retry import Retry
Expand Down Expand Up @@ -242,8 +242,13 @@ def _fixup_image_query(iq: ImageQuery) -> ImageQuery:
"""
# Note: This might go away once we clean up the mapping logic server-side.

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

Expand Down
Loading