Skip to content

Commit d783dfa

Browse files
brandon-wadaAuto-format Bot
andauthored
quick fix to support counting unclear in the SDK (#299)
This is a potential patch for handling unclear results for counting detectors --------- Co-authored-by: Auto-format Bot <[email protected]>
1 parent d57d43a commit d783dfa

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

generated/docs/CountingResult.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Properties
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
7-
**count** | **int** | |
7+
**count** | **int, none_type** | |
88
**confidence** | **float** | | [optional]
99
**source** | **str** | | [optional]
1010
**greater_than_max** | **bool** | | [optional]

generated/groundlight_openapi_client/model/counting_result.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ def openapi_types():
104104
and the value is attribute type.
105105
"""
106106
return {
107-
"count": (int,), # noqa: E501
107+
"count": (
108+
int,
109+
none_type,
110+
), # noqa: E501
108111
"confidence": (float,), # noqa: E501
109112
"source": (str,), # noqa: E501
110113
"greater_than_max": (bool,), # noqa: E501
@@ -131,7 +134,7 @@ def _from_openapi_data(cls, count, *args, **kwargs): # noqa: E501
131134
"""CountingResult - a model defined in OpenAPI
132135
133136
Args:
134-
count (int):
137+
count (int, none_type):
135138
136139
Keyword Args:
137140
_check_type (bool): if True, values for parameters in openapi_types
@@ -222,7 +225,7 @@ def __init__(self, count, *args, **kwargs): # noqa: E501
222225
"""CountingResult - a model defined in OpenAPI
223226
224227
Args:
225-
count (int):
228+
count (int, none_type):
226229
227230
Keyword Args:
228231
_check_type (bool): if True, values for parameters in openapi_types

generated/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: public-api.yaml
3-
# timestamp: 2024-12-13T20:10:31+00:00
3+
# timestamp: 2024-12-19T17:53:53+00:00
44

55
from __future__ import annotations
66

@@ -200,7 +200,7 @@ class BinaryClassificationResult(BaseModel):
200200
class CountingResult(BaseModel):
201201
confidence: Optional[confloat(ge=0.0, le=1.0)] = None
202202
source: Optional[Source] = None
203-
count: conint(ge=0)
203+
count: Optional[conint(ge=0)] = Field(...)
204204
greater_than_max: Optional[bool] = None
205205

206206

spec/public-api.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ components:
13811381
count:
13821382
type: integer
13831383
minimum: 0
1384+
nullable: true
13841385
greater_than_max:
13851386
type: boolean
13861387
required:

src/groundlight/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ def get_image_query(self, id: str) -> ImageQuery: # pylint: disable=redefined-b
527527
:return: ImageQuery object containing the query details and results
528528
"""
529529
obj = self.image_queries_api.get_image_query(id=id, _request_timeout=DEFAULT_REQUEST_TIMEOUT)
530+
if obj.result_type == "counting" and getattr(obj.result, "label", None):
531+
obj.result.pop("label")
532+
obj.result["count"] = None
530533
iq = ImageQuery.parse_obj(obj.to_dict())
531534
return self._fixup_image_query(iq)
532535

test/unit/test_labels.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@ def test_counting_labels(gl_experimental: ExperimentalApi):
2525
name = f"Test binary labels{datetime.utcnow()}"
2626
det = gl_experimental.create_counting_detector(name, "test_query", "test_object_class")
2727
iq1 = gl_experimental.submit_image_query(det, "test/assets/cat.jpeg")
28+
2829
gl_experimental.add_label(iq1, 0)
2930
iq1 = gl_experimental.get_image_query(iq1.id)
3031
assert iq1.result.count == 0
32+
3133
good_label = 5
3234
gl_experimental.add_label(iq1, good_label)
3335
iq1 = gl_experimental.get_image_query(iq1.id)
3436
assert iq1.result.count == good_label
37+
38+
gl_experimental.add_label(iq1, "UNCLEAR")
39+
iq1 = gl_experimental.get_image_query(iq1.id)
40+
assert iq1.result.count is None
41+
3542
with pytest.raises(ApiException) as _:
3643
gl_experimental.add_label(iq1, "MAYBE")
3744
with pytest.raises(ApiException) as _:

0 commit comments

Comments
 (0)