feat: a live path that uses the enrolled store, and a demo server a phone can reach
The live session scored crops with the matcher regardless of the configured identity backend, so a live scan used the old mechanism while the still path used the enrolled gallery - measured, the matcher accepts look-alikes and cannot say "unknown", which is exactly what a real shelf needs it to do. score_crop now routes to the gallery, and the decision uses a similarity scale (accept at 0.60 with a 0.04 margin) rather than inlier-count thresholds that mean nothing on a cosine. The synthetic walk is gone: demo.py, demo_replay.py, the /v1/demo endpoints and the walk benchmark are deleted, and the app's frame source is the camera on a device (the single-image replay stays for the simulator, which has no camera). stock-demo merges both demo shelves (27 products, 62 views, trained head) so one server recognises either image, and run-demo-server.sh starts it bound to 0.0.0.0 and prints the exact URL to put in Config.xcconfig. Verified over the LAN with 1280x960 frames: 40 frames in 5.3s, 9 products recognised on demo image 1. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
383ff9cf2d
commit
0e23425ef0
74 changed files with 158 additions and 767 deletions
|
|
@ -25,6 +25,13 @@ def relative_confidence(top_score: float, runner_up_score: float) -> float:
|
|||
return round(min(1.0, top_score / max(1.0, (top_score + runner_up_score * 0.5))), 4)
|
||||
|
||||
|
||||
# The gallery's scale is a cosine similarity, where same-product pairs sit above 0.6
|
||||
# and different products below 0.5 - not an inlier count, which has no such meaning.
|
||||
COSINE_ACCEPT = 0.60
|
||||
COSINE_AMBIGUOUS = 0.50
|
||||
COSINE_MARGIN = 0.04
|
||||
|
||||
|
||||
def decide_identity(
|
||||
scores: Dict[str, float],
|
||||
*,
|
||||
|
|
@ -33,6 +40,7 @@ def decide_identity(
|
|||
min_confidence: float = DEFAULT_MIN_CONFIDENCE,
|
||||
details: Optional[Dict[str, Any]] = None,
|
||||
method: str = "hybrid",
|
||||
scale: str = "inlier",
|
||||
) -> Dict[str, Any]:
|
||||
"""Rank catalog scores into accepted / ambiguous / unknown / rejected.
|
||||
|
||||
|
|
@ -56,6 +64,30 @@ def decide_identity(
|
|||
sorted_candidates: List[Tuple[str, float]] = sorted(
|
||||
scores.items(), key=lambda x: x[1], reverse=True
|
||||
)
|
||||
if scale == "cosine":
|
||||
# Thresholds that mean something on a similarity scale.
|
||||
top_sku, top_score = sorted_candidates[0]
|
||||
runner_score = sorted_candidates[1][1] if len(sorted_candidates) > 1 else 0.0
|
||||
margin = top_score - runner_score
|
||||
if top_score >= COSINE_ACCEPT and margin >= COSINE_MARGIN:
|
||||
level = IDENTITY_ACCEPTED
|
||||
elif top_score >= COSINE_AMBIGUOUS:
|
||||
level = IDENTITY_AMBIGUOUS
|
||||
else:
|
||||
level = IDENTITY_REJECTED
|
||||
return {
|
||||
"status": level,
|
||||
"method": method,
|
||||
"best_sku": top_sku if level == IDENTITY_ACCEPTED else None,
|
||||
"score": float(top_score),
|
||||
"confidence": float(top_score),
|
||||
"identity_level": level,
|
||||
"ranked_candidates": [
|
||||
{"sku_id": sku, "score": float(value)} for sku, value in sorted_candidates[:3]
|
||||
],
|
||||
"details": details or {},
|
||||
"message": None,
|
||||
}
|
||||
top_sku, top_score = sorted_candidates[0]
|
||||
runner_up_sku, runner_up_score = (
|
||||
sorted_candidates[1] if len(sorted_candidates) > 1 else (None, 0.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue