Skip to content

Commit

Permalink
Added confidence message
Browse files Browse the repository at this point in the history
  • Loading branch information
honeytung committed Jul 3, 2024
1 parent 2b715bc commit 6e27aa0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 4 additions & 2 deletions app/api/routes/image_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@ async def post_image_query(
new_image_query = motion_detection_manager.get_image_query_response(detector_id=detector_id).copy(
deep=True, update={"id": prefixed_ksuid(prefix="iqe_")}
)

logger.debug(f"Motion detection - Current confidence: {new_image_query.result.confidence}. "
f"Target confidence: {confidence_threshold}.")

if new_image_query.result and _is_confident_enough(
confidence=new_image_query.result.confidence,
detector_metadata=get_detector_metadata(detector_id=detector_id, gl=gl),
confidence_threshold=confidence_threshold,
):
logger.debug(f"Motion detection confidence is high enough to return. Current confidece: "
f"{new_image_query.result.confidence}. Target confidence: {confidence_threshold}.")
logger.debug("Motion detection confidence is high enough to return.")
app_state.db_manager.create_iqe_record(record=new_image_query)
return new_image_query

Expand Down
7 changes: 0 additions & 7 deletions test/api/test_motdet.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,15 @@ def test_motion_detection_not_sufficient_if_doesnt_meet_conf_threshold(gl: Groun
or base_iq_response.result.confidence == 1.0
):
pytest.skip("This test requires that the cached image query response has a confidence < 1.0")

current_time = time.time()

new_response = gl.submit_image_query(
detector=detector.id,
image=original_image,
wait=wait_time,
confidence_threshold=base_iq_response.result.confidence + 1e-3, # Require a higher confidence than before
)

time_diff = time.time() - current_time

assert new_response.id != base_iq_response.id, "ImageQuery id should be different whether or not motion det is run"

# If the time difference exceeded the wait time, that means the ML has time out and will just return the previous
# result
assert new_response.id.startswith("iq_"), (
"ImageQuery id should start with 'iq_' because it was created on the cloud, because the cached mot det "
"response did not meet the confidence threshold"
Expand Down

0 comments on commit 6e27aa0

Please sign in to comment.