-
Notifications
You must be signed in to change notification settings - Fork 3
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
Ask_async docs #113
Merged
Merged
Ask_async docs #113
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
52003f7
bump version
brandon-groundlight 7c319b1
Update UNSURE to be UNCLEAR, catch __USURE received from the service …
brandon-groundlight 7bb71b1
rough draft of demo
sunildkumar 0a7b928
ask_async (#102)
sunildkumar 59dcc76
Cli polishing (#109)
brandon-groundlight 9eecd10
Add ask_confident and ask_ml (#99)
brandon-groundlight a60d888
Linting
brandon-groundlight 57ca951
Merge branch 'main' into version_0.12.0
brandon-groundlight d465d4c
Merge branch 'main' into ask_async_docs
sunildkumar 6647bce
addressed self comments
sunildkumar 2e935f8
Merge branch 'version_0.12.0' into ask_async_docs
sunildkumar 3391b7e
fix ask_async docstring
sunildkumar a88d01e
small fixes
sunildkumar 1df815e
cleaning up a bit
sunildkumar e9f6065
Merge branch 'main' into version_0.12.0
sunildkumar 0e3446a
Merge branch 'version_0.12.0' into ask_async_docs
sunildkumar af83bad
Update docs/docs/building-applications/5-async-queries.md
sunildkumar 5dccedf
Update docs/docs/building-applications/5-async-queries.md
sunildkumar 6dc91fc
small fixes based on PR feedback from Leo and Blaise
sunildkumar 1841dd2
Merge branch 'main' into ask_async_docs
sunildkumar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ng-applications/working-with-detectors.md → ...-applications/2-working-with-detectors.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
sidebar_position: 3 | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Working with Detectors | ||
|
3 changes: 3 additions & 0 deletions
3
...ing-applications/5-managing-confidence.md → ...ing-applications/3-managing-confidence.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
.../building-applications/handling-errors.md → ...uilding-applications/4-handling-errors.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
sidebar_position: 5 | ||
--- | ||
|
||
# Asynchronous Queries | ||
|
||
Groundlight provides a simple interface for submitting asynchronous queries. This is useful for times in which the thread or machine submitting image queries is not the same thread or machine that will be retrieving and using the results. For example, you might have a forward deployed robot or camera that submits image queries to Groundlight, and a separate server that retrieves the results and takes action based on them. We will refer to these two machines as the **submitting machine** and the **retrieving machine**. | ||
sunildkumar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Setup Submitting Machine | ||
On the **submitting machine**, you will need to install the Groundlight Python SDK. Then you can submit image queries asynchronously using the `ask_async` interface (read the full documentation [here](pathname:///python-sdk/api-reference-docs/#groundlight.client.Groundlight.ask_async)). `ask_async` submits your query and returns as soon as the query is submitted. It does not wait for an answer to be available prior to returning to minimize the time your program spends interacting with Groundlight. As a result, the `ImageQuery` object `ask_async` returns lacks a `result` (the `result` field will `None`). This is acceptable for this use case as the **submitting machine** is not interested in the result. Instead, the **submitting machine** just needs to communicate the `ImageQuery.id`s to the **retrieving machine** - this might be done via a database, a message queue, or some other mechanism. For this example, we assume you are using a database where you save the `ImageQuery.id` to it via `db.save(image_query.id)`. | ||
sunildkumar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```python notest | ||
from groundlight import Groundlight | ||
import cv2 | ||
from time import sleep | ||
|
||
detector = gl.get_or_create_detector(name="your_detector_name", query="your_query") | ||
|
||
cam = cv2.VideoCapture(0) # Initialize camera (0 is the default index) | ||
|
||
while True: # TODO: add a way to exit this loop... not sure what makes sense here | ||
sunildkumar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_, image = cam.read() # Capture one frame from the camera | ||
image_query = gl.ask_async(detector=detector, image=image) # Submit the frame to Groundlight | ||
db.save(image_query.id) # Save the image_query.id to a database for the retrieving machine to use | ||
sleep(10) # Sleep for 10 seconds before submitting the next query | ||
|
||
cam.release() # Release the camera | ||
|
||
``` | ||
|
||
## Setup Retrieving Machine | ||
On the **retrieving machine** you will need to install the Groundlight Python SDK. Then you can retrieve the results of the image queries submitted by another machine using `get_image_query`. The **retrieving machine** can then use the `ImageQuery.result` to take action based on the result for whatever application you are building. For this example, we assume your application looks up the next image query to process from a database via `db.get_next_image_query_id()` and that this function returns `None` once all `ImageQuery`s are processed. | ||
```python notest | ||
from groundlight import Groundlight | ||
|
||
detector = gl.get_or_create_detector(name="your_detector_name", query="your_query") | ||
|
||
image_query_id = db.get_next_image_query_id() | ||
|
||
while image_query_id is not None: | ||
image_query = gl.get_image_query(id=image_query_id) # retrieve the image query from Groundlight | ||
result = image_query.result | ||
|
||
# take action based on the result of the image query | ||
if result.label == 'YES': | ||
pass # TODO: do something based on your application | ||
elif result.label == 'NO': | ||
pass # TODO: do something based on your application | ||
elif result.label == 'UNCLEAR': | ||
pass # TODO: do something based on your application | ||
|
||
# update image_query_id for next iteration of the loop | ||
image_query_id = db.get_next_image_query_id() | ||
``` | ||
|
||
## Important Considerations | ||
When you submit an image query asynchronously, ML prediction on your query is **not** instant. So attempting to retrieve the result immediately after submitting the query will likely result in an `UNCLEAR` result as Groundlight is still processing your query. Instead, if your code needs a `result` synchronously we recommend using one of our methods with a polling mechanism to retrieve the result. You can see all of the interfaces available in the documentation [here](pathname:///python-sdk/api-reference-docs/#groundlight.client.Groundlight). | ||
|
||
```python notest | ||
from groundlight import Groundlight | ||
from PIL import Image | ||
|
||
detector = gl.get_or_create_detector(name="your_detector_name", query="your_query") | ||
image = Image.open("/path/to/your/image.jpg") | ||
image_query = gl.ask_async(detector=detector, image=image) # Submit the frame to Groundlight | ||
result = image_query.result # This will likely be 'UNCLEAR' as Groundlight is still processing your query | ||
sunildkumar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
# TODO: what other considerations are there? | ||
sunildkumar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
6 changes: 5 additions & 1 deletion
6
docs/docs/building-applications/edge.md → docs/docs/building-applications/6-edge.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
.../docs/building-applications/industrial.md → ...ocs/building-applications/7-industrial.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explicitly gave each of the docs in /building-applications a place in the sidebar list by prepending each one with
<{position}->
and addingsidebar_position: {position}
where necessary.