From f75ee629d1937e79bf81c6398326fef55256947c Mon Sep 17 00:00:00 2001 From: EVA x10 Development Date: Wed, 25 Nov 2026 15:23:13 +0100 Subject: [PATCH] Log track transitions and visitor matching decisions --- AndroidManifest.xml | 2 +- README.md | 8 ++++---- build.sh | 4 ++-- poc/src/FaceReId.java | 24 +++++++++++++++++++----- src/MainActivity.java | 17 ++++++++++++++++- src/ReIdProvider.java | 1 + src/VisitorSessions.java | 8 ++++++++ 7 files changed, 51 insertions(+), 13 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2ce2ff0..14b3fea 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.it_screen.edgevision" android:versionCode="25" android:versionName="0.3.20"> diff --git a/README.md b/README.md index 41b1da6..db48db5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# EVAx10 Video analitics v0.3.19 +# EVAx10 Video analitics v0.3.20 A separate native Android experiment for consenting adult volunteers. Package `com.it_screen.edgevision`. The existing FaceAPI baseline is @@ -10,10 +10,10 @@ installable as `com.it_screen.audiencepoc`. `./build.sh` builds the ARM64, API 30+ APK with the Windows Android SDK 35 and JDK 17 via WSL. The script pins and verifies the upstream Maven AAR. Model assets load locally and are verified before ONNX Runtime session -creation. The signed test build is `build/EVAx10-Video-analitics-0.3.19.apk`. +creation. The signed test build is `build/EVAx10-Video-analitics-0.3.20.apk`. ```text -adb install --no-incremental -r EVAx10-Video-analitics-0.3.19.apk +adb install --no-incremental -r EVAx10-Video-analitics-0.3.20.apk adb shell am start -W -n com.it_screen.edgevision/.MainActivity adb logcat -s EdgeVision EdgeVisionBench ``` @@ -96,7 +96,7 @@ or an Android low-memory signal is red. ### Controlled Face Re-ID PoC Build with `./build.sh --face-reid-poc`. Install -`build/EVAx10-Video-analitics-0.3.19-Face-ReID-PoC.apk` as the separate package +`build/EVAx10-Video-analitics-0.3.20-Face-ReID-PoC.apk` as the separate package `com.it_screen.edgevision.facereidpoc`. Start requires on-device confirmation that all adult test participants consent. Keep other people out of the camera view. The default build excludes the SFace weights and implementation. diff --git a/build.sh b/build.sh index b5f8181..dcfb62a 100755 --- a/build.sh +++ b/build.sh @@ -20,14 +20,14 @@ if [[ ! -f build/ort.aar ]]; then fi python3 tools/check-production-assets.py manifest=AndroidManifest.xml -apk=build/EVAx10-Video-analitics-0.3.19.apk +apk=build/EVAx10-Video-analitics-0.3.20.apk if [[ $variant == poc ]]; then python3 tools/check-poc-assets.py manifest=build/AndroidManifest-face-reid-poc.xml sed -e 's/package="com.it_screen.edgevision"/package="com.it_screen.edgevision.facereidpoc"/' \ -e 's/android:name=".MainActivity"/android:name="com.it_screen.edgevision.MainActivity"/' \ AndroidManifest.xml > "$manifest" - apk=build/EVAx10-Video-analitics-0.3.19-Face-ReID-PoC.apk + apk=build/EVAx10-Video-analitics-0.3.20-Face-ReID-PoC.apk fi rm -rf build/classes build/dex mkdir -p build/classes build/dex diff --git a/poc/src/FaceReId.java b/poc/src/FaceReId.java index 26ec350..390dc7a 100644 --- a/poc/src/FaceReId.java +++ b/poc/src/FaceReId.java @@ -23,6 +23,9 @@ final class FaceReId implements ReIdProvider { } private ImageModel model; private float threshold; + private String matchDetails = ""; + + @Override public String matchDetails() { return matchDetails; } static ReIdProvider create() { return new FaceReId(); } @@ -91,19 +94,30 @@ final class FaceReId implements ReIdProvider { if (observation == null) return UNCERTAIN; long bestId = 0; float best = -2, runnerUp = -2; - boolean missing = false; + int comparable = 0; + long runnerUpId = 0; for (VisitorSessions.Candidate candidate : candidates) { Enrollment enrollment = templates.get(candidate.id); - if (enrollment == null) { missing = true; continue; } + if (enrollment == null) continue; + comparable++; float similarity = bestSimilarity(observation, enrollment); if (similarity > best) { runnerUp = best; + runnerUpId = bestId; best = similarity; bestId = candidate.id; - } else runnerUp = Math.max(runnerUp, similarity); + } else if (similarity > runnerUp) { + runnerUp = similarity; + runnerUpId = candidate.id; + } } - if (best >= threshold && best - runnerUp >= AMBIGUITY_MARGIN) return bestId; - return missing || best >= threshold - AMBIGUITY_MARGIN ? UNCERTAIN : 0; + long result = best >= threshold && best - runnerUp >= AMBIGUITY_MARGIN ? bestId : + comparable < candidates.size() || best >= threshold - AMBIGUITY_MARGIN ? UNCERTAIN : 0; + matchDetails = String.format(java.util.Locale.ROOT, + "comparable=%d best=V%d:%.3f runner_up=V%d:%.3f threshold=%.3f margin=%.3f result=%s", + comparable, bestId, best, runnerUpId, runnerUp, threshold, AMBIGUITY_MARGIN, + result > 0 ? "match" : result == 0 ? "below_distinct_cutoff" : "uncertain"); + return result; } @Override public void observed(long visitorId, float[] observation) { diff --git a/src/MainActivity.java b/src/MainActivity.java index 160545f..0d6158f 100644 --- a/src/MainActivity.java +++ b/src/MainActivity.java @@ -691,8 +691,9 @@ public final class MainActivity extends Activity { } for (PersonTracker.Track track : tracker.tracks()) { if (track.state != PersonTracker.State.ACTIVE) continue; + Face observedFace = assignments.get(track); float[] sample = visitorSessions.needsObservation(track.id) ? - FaceReId.embed(reId, frame, assignments.get(track)) : null; + FaceReId.embed(reId, frame, observedFace) : null; boolean awaitMoreEvidence = FaceReId.CONTROLLED_POC && now - track.activeSince < 5000L; VisitorSessions.Assignment assignment; @@ -701,6 +702,18 @@ public final class MainActivity extends Activity { } finally { if (sample != null) Arrays.fill(sample, 0); } + if (FaceReId.CONTROLLED_POC && assignment.kind != VisitorSessions.Kind.CONTINUED && + (faceMs >= 0 || assignment.kind != VisitorSessions.Kind.DEFERRED)) { + String faceDetails = observedFace == null ? "no_associated_face" : + String.format(Locale.ROOT, "%.0fx%.0fpx confidence=%.3f eyes_px=%.1f", + observedFace.box.width() * frame.getWidth(), observedFace.box.height() * frame.getHeight(), + observedFace.confidence, observedFace.landmarks == null ? -1 : + Math.hypot(observedFace.landmarks[2] - observedFace.landmarks[0], + observedFace.landmarks[3] - observedFace.landmarks[1])); + android.util.Log.i("EdgeVisionTrack", "decision track=" + track.id + " kind=" + assignment.kind + + " visitor=" + assignment.visitorId + " unique=" + visitorSessions.totalCreated() + + " face=" + faceDetails + " embedding=" + (sample != null) + " " + visitorSessions.observationDetails()); + } if (FaceReId.CONTROLLED_POC) visitorSessions.updateAge(track.id, track.analytics.averageAge()); switch (assignment.kind) { case RECONNECTED: @@ -868,6 +881,7 @@ public final class MainActivity extends Activity { } private void addVisitEvent(String event) { + if (FaceReId.CONTROLLED_POC) android.util.Log.i("EdgeVisionTrack", event); if (visitEvents.size() == 30) visitEvents.removeLast(); visitEvents.addFirst("[" + eventClock.format(new Date()) + "] " + event); } @@ -881,6 +895,7 @@ public final class MainActivity extends Activity { private void reset() { inference.execute(() -> { + if (FaceReId.CONTROLLED_POC) android.util.Log.i("EdgeVisionTrack", "RESET statistics"); tracker.clear(); visitorSessions.clear(); visitEvents.clear(); diff --git a/src/ReIdProvider.java b/src/ReIdProvider.java index 2a30ee3..934febe 100644 --- a/src/ReIdProvider.java +++ b/src/ReIdProvider.java @@ -7,6 +7,7 @@ interface ReIdProvider { long UNCERTAIN = -1; boolean enabled(); + default String matchDetails() { return ""; } default boolean enrollmentComplete(long visitorId) { return false; } /** Return a confidently matched candidate ID, zero for a distinct visitor, or UNCERTAIN when evidence is insufficient. */ diff --git a/src/VisitorSessions.java b/src/VisitorSessions.java index c838bab..1d5cd5e 100644 --- a/src/VisitorSessions.java +++ b/src/VisitorSessions.java @@ -18,6 +18,10 @@ final class VisitorSessions { private final Map byTrack = new HashMap<>(); private final Set unresolved = new HashSet<>(); private final int[] ageCounts = new int[AudienceAggregator.AGES.length]; + private String observationDetails = ""; + + String observationDetails() { return observationDetails; } + private long nextId = 1; private long totalCreated, repeated, uncertain; @@ -76,6 +80,7 @@ final class VisitorSessions { } Assignment observe(int trackId, long now, Observation observation, boolean awaitMoreEvidence) { + observationDetails = ""; Session session = byTrack.get(trackId); Kind kind = Kind.CONTINUED; if (session == null) { @@ -86,10 +91,13 @@ final class VisitorSessions { for (Session candidate : open.values()) { if (!candidate.visible) candidates.add(new Candidate(candidate.id, candidate.lastSeen)); } + observationDetails = "eligible=" + candidates.size() + " open=" + open.size() + + " waiting=" + awaitMoreEvidence; if (awaitMoreEvidence && observation == null) return new Assignment(0, Kind.DEFERRED); if (observation == null) match = ReIdProvider.UNCERTAIN; else if (!candidates.isEmpty()) { match = provider.match(observation, Collections.unmodifiableList(candidates)); + observationDetails += " " + provider.matchDetails(); Session candidate = open.get(match); if (candidate != null && !candidate.visible) { session = candidate;