Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait_for_confident_result does not gracefully handle default confidence value if using ImageQuery object for detection #312

Open
petermuller opened this issue Feb 3, 2025 · 0 comments

Comments

@petermuller
Copy link

petermuller commented Feb 3, 2025

Issue and replication

Hi team! I'm testing out the Groundlight API and came across a crash in my basic proof-of-concept script that I wanted to report. The core problem I found was when doing async analysis, I'm able to submit images fine, but then when I want to await the results, I'm hit with a type checking error:

edit: pip freeze shows me at version groundlight==0.21.3

Traceback (most recent call last):
  File "C:\path\to\my\groundlight_ws\groundlight_demo.py", line 40, in <module>
    results.append(gl.wait_for_confident_result(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\path\to\my\groundlight_ws\venv\Lib\site-packages\groundlight\client.py", line 1002, in wait_for_confident_result
    return self._wait_for_result(image_query, condition=confidence_above_thresh, timeout_sec=timeout_sec)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\path\to\my\groundlight_ws\venv\Lib\site-packages\groundlight\client.py", line 1065, in _wait_for_result
    if condition(image_query):
       ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\path\to\my\groundlight_ws\venv\Lib\site-packages\groundlight\internalapi.py", line 70, in iq_is_confident
    return iq.result.confidence >= confidence_threshold  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'float' and 'NoneType'

To get here, a barebones sample of what I've done is here:

import os
from groundlight import Groundlight, Detector

API_TOKEN = "mytoken"
os.environ["GROUNDLIGHT_API_TOKEN"] = API_TOKEN


gl = Groundlight()
det: Detector = gl.get_or_create_detector(
    name="my_binary_detector",
    query="Is the door open?"
)

queries = []
for i in range(1,5):  # submit 4 images to the detector
    print(f"submitting image s{i}.png")  # just using local filenames as strings
    queries.append(gl.ask_async(detector=det, image=f"s{i}.png"))


results = []
for q in queries:
    results.append(gl.wait_for_confident_result(
        #### PROBLEM HERE ### I'm not specifying a confidence value, which should default to the detector's value,
        #### and I am using the image query object instead of the query string ID.
        image_query=q
    ))

# <... further processing / not needed for issue replication ...>

Based on function signatures, the iq_is_confident function does not expect a None type in the confidence_value, and the wait_for_confident_result method will supply a None if the confidence_threshold is omitted and when the type of the image_query is not a string, as in it's an ImageQuery object.


After looking at the code more, it also looks like this method will override the user's confidence_threshold in the case that the string version of the ImageQuery is provided since that variable gets overridden here - I only bring that up because it runs counter to the docstring

Expected behavior

For my main bug: My anticipated behavior for this would be that my detector's threshold of 0.9 is used if I didn't specify a threshold
For the secondary one: Anticipated behavior is that the confidence threshold provided to wait_for_confident_result would be used instead of my detector's 0.9 threshold value if I provided the detector's string ID.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant